]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
some reindentation, revert workarea xpos++, constify, remove all traces of LyXParagra...
[lyx.git] / src / insets / insettext.C
index 3bbcdf9bbfa5691ac2f3510034b0cdbd0af59a2a..b4aead7368dadb18d88da3387c3a808cd7607237 100644 (file)
@@ -37,7 +37,6 @@
 #include "lyxcursor.h"
 #include "CutAndPaste.h"
 #include "font.h"
-#include "minibuffer.h"
 #include "LColor.h"
 #include "support/textutils.h"
 #include "support/LAssert.h"
@@ -47,6 +46,8 @@
 #include "trans_mgr.h"
 #include "lyxscreen.h"
 #include "WorkArea.h"
+#include "gettext.h"
+#include "lyxfunc.h"
 
 using std::ostream;
 using std::ifstream;
@@ -60,7 +61,7 @@ extern int greek_kb_flag;
 
 InsetText::InsetText()
 {
-       par = new LyXParagraph();
+       par = new LyXParagraph;
        init();
 }
 
@@ -91,27 +92,25 @@ void InsetText::init(InsetText const * ins)
        insetDescent = 0;
        insetWidth = 0;
        the_locking_inset = 0;
-#if 0
-       cursor_visible = false;
-#endif
        interline_space = 1;
        no_selection = false;
        need_update = INIT;
        drawTextXOffset = 0;
        drawTextYOffset = 0;
        autoBreakRows = false;
-       drawFrame = NEVER;
+       drawFrame_ = NEVER;
        xpos = 0.0;
        if (ins) {
-       SetParagraphData(ins->par);
-       autoBreakRows = ins->autoBreakRows;
-       drawFrame = ins->drawFrame;
+               SetParagraphData(ins->par);
+               autoBreakRows = ins->autoBreakRows;
+               drawFrame_ = ins->drawFrame_;
        }
        par->SetInsetOwner(this);
        frame_color = LColor::insetframe;
        locked = false;
        old_par = 0;
        last_drawn_width = -1;
+       frame_is_visible = false;
 }
 
 
@@ -119,27 +118,16 @@ InsetText::~InsetText()
 {
        // delete all instances of LyXText before deleting the paragraps used
        // by it.
-       for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){
-       delete (*cit).second;
-       (*cit).second = 0;
-       }
-#ifndef NEW_INSETS
-       LyXParagraph * p = par->next_;
-       delete par;
-       while(p) {
-       par = p;
-       p = p->next_;
-       delete par;
+       for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
+               delete (*cit).second;
+               (*cit).second = 0;
        }
-#else
-       LyXParagraph * p = par->next();
-       delete par;
-       while(p) {
-       par = p;
-       p = p->next();
-       delete par;
+
+       while (par) {
+               LyXParagraph * tmp = par->next();
+               delete par;
+               par = tmp;
        }
-#endif
 }
 
 
@@ -147,28 +135,17 @@ void InsetText::clear()
 {
        // delete all instances of LyXText before deleting the paragraps used
        // by it.
-       for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){
+       for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
                delete (*cit).second;
                (*cit).second = 0;
        }
-#ifndef NEW_INSETS
-       LyXParagraph * p = par->next_;
-       delete par;
-       while(p) {
-               par = p;
-               p = p->next_;
-               delete par;
-       }
-#else
-       LyXParagraph * p = par->next();
-       delete par;
-       while(p) {
-               par = p;
-               p = p->next();
+
+       while (par) {
+               LyXParagraph * tmp = par->next();
                delete par;
+               par = tmp;
        }
-#endif
-       par = new LyXParagraph();
+       par = new LyXParagraph;
 }
 
 
@@ -198,37 +175,10 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex)
        int pos = 0;
        LyXParagraph * return_par = 0;
        char depth = 0; // signed or unsigned?
-#ifndef NEW_INSETS
-       LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
-       LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
-#endif
        LyXFont font(LyXFont::ALL_INHERIT);
 
-       // delete all instances of LyXText before deleting the paragraps used
-       // by it.
-       for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
-               delete (*cit).second;
-               (*cit).second = 0;
-       }
-
-#ifndef NEW_INSETS
-       LyXParagraph * p = par->next_;
-       delete par;
-       while(p) {
-               par = p;
-               p = p->next_;
-               delete par;
-       }
-#else
-       LyXParagraph * p = par->next();
-       delete par;
-       while(p) {
-               par = p;
-               p = p->next();
-               delete par;
-       }
-#endif
-       par = new LyXParagraph;
+       clear();
+       
        while (lex.IsOK()) {
                lex.nextToken();
                token = lex.GetString();
@@ -237,13 +187,8 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex)
                if (token == "\\end_inset")
                        break;
                if (const_cast<Buffer*>(buf)->
-                       parseSingleLyXformat2Token(lex, par, return_par,token, pos, depth,
-                                                                          font
-#ifndef NEW_INSETS
-                                                                          , footnoteflag, footnotekind
-#endif
-                                                                          ))
-               {
+                       parseSingleLyXformat2Token(lex, par, return_par,
+                                                  token, pos, depth, font)) {
                        // the_end read this should NEVER happen
                        lex.printError("\\the_end read in inset! Error in document!");
                        return;
@@ -254,11 +199,7 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex)
        par = return_par;
        while(return_par) {
                return_par->SetInsetOwner(this);
-#ifndef NEW_INSETS
-               return_par = return_par->next_;
-#else
                return_par = return_par->next();
-#endif
        }
        
        if (token != "\\end_inset") {
@@ -304,28 +245,31 @@ int InsetText::textWidth(BufferView * bv) const
 
 
 void InsetText::draw(BufferView * bv, LyXFont const & f,
-                        int baseline, float & x, bool cleared) const
+                     int baseline, float & x, bool cleared) const
 {
+       if (nodraw())
+               return;
+
        Painter & pain = bv->painter();
 
        // no draw is necessary !!!
-       if ((drawFrame == LOCKED) && !locked && !par->size()) {
-               if (!cleared && (need_update & CLEAR_FRAME)) {
-                       pain.rectangle(top_x + 1, baseline - insetAscent + 1,
-                                                  width(bv, f) - 1,
-                                                  insetAscent + insetDescent - 1,
-                                                  LColor::background);
-               }
+       if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
                top_x = int(x);
                top_baseline = baseline;
                x += width(bv, f);
+               if (!cleared && (need_update & CLEAR_FRAME))
+                       clearFrame(pain, cleared);
                need_update = NONE;
                return;
        }
 
        xpos = x;
+#if 0
        UpdatableInset::draw(bv, f, baseline, x, cleared);
-
+#else
+       if (!owner())
+               x += static_cast<float>(scroll());
+#endif
        // update insetWidth and insetHeight with dummy calls
        (void)ascent(bv, f);
        (void)descent(bv, f);
@@ -333,7 +277,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        // if top_x differs we have a rule down and we don't have to clear anything
        if (!cleared && (top_x == int(x)) &&
-               ((need_update==INIT)||(need_update==FULL)||(top_baseline!=baseline) ||
+               ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
                 (last_drawn_width!=insetWidth)))
        {
                int w =  insetWidth;
@@ -356,11 +300,14 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                return;
 
        if (top_x != int(x)) {
-               need_update = INIT;
+               need_update |= INIT;
                top_x = int(x);
                bv->text->status = LyXText::CHANGED_IN_DRAW;
                return;
        }
+
+//     lyxerr << "InsetText::draw[" << this << "](" << need_update << ":" << int(x) << ":" << top_x << ")\n";
+
        if (cleared || (last_drawn_width != insetWidth)) {
                need_update |= FULL;
                last_drawn_width = insetWidth;
@@ -376,11 +323,18 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                inset_y = cy(bv) + drawTextYOffset;
        }
        if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) {
+               drawFrame(pain, cleared);
                x += width(bv, f);
                need_update = NONE;
                return;
        }
        x += TEXT_TO_INSET_OFFSET;
+
+#ifdef WITH_WARNINGS
+#warning Jürgen, why is this a block of its own? (Lgb)
+#warning because you told me to define variables only in local context (Jug)!
+#warning then make it a function/method of its own. (Lgb)
+#endif
        {
        int y = 0;
        Row * row = TEXT(bv)->GetRowNearY(y);
@@ -396,7 +350,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        if (y_offset < 0)
                y_offset = y;
        TEXT(bv)->first = first;
-       if (cleared) { // (need_update&FULL) || (need_update&INIT)
+       if (cleared) {
                int yf = y_offset;
                y = 0;
                while ((row != 0) && (yf < ph)) {
@@ -429,28 +383,46 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        TEXT(bv)->refresh_y = 0;
        TEXT(bv)->status = LyXText::UNCHANGED;
        if ((need_update != CURSOR_PAR) &&
-               ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)))
-       {
-               pain.rectangle(top_x + 1, baseline - insetAscent + 1,
-                                          width(bv, f) - 1, insetAscent + insetDescent - 1,
-                                          frame_color);
-       } else if (need_update & CLEAR_FRAME) {
-               pain.rectangle(top_x + 1, baseline - insetAscent + 1,
-                                          width(bv, f) - 1, insetAscent + insetDescent - 1,
-                                          LColor::background);
-       }
+               ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
+               drawFrame(pain, cleared);
+       else if (need_update & CLEAR_FRAME)
+               clearFrame(pain, cleared);
        x += width(bv, f) - TEXT_TO_INSET_OFFSET;
        if (bv->text->status==LyXText::CHANGED_IN_DRAW) {
-               need_update = INIT;
+               need_update |= INIT;
        } else if (need_update != INIT)
                need_update = NONE;
 }
 
 
+void InsetText::drawFrame(Painter & pain, bool cleared) const
+{
+       if (!frame_is_visible || cleared) {
+               pain.rectangle(top_x + 1, top_baseline - insetAscent + 1,
+                              insetWidth - 1, insetAscent + insetDescent - 1,
+                              frame_color);
+               frame_is_visible = true;
+       }
+}
+
+
+void InsetText::clearFrame(Painter & pain, bool cleared) const
+{
+       if (frame_is_visible) {
+               if (!cleared) {
+                       pain.rectangle(top_x + 1, top_baseline - insetAscent + 1,
+                                      insetWidth - 1, insetAscent + insetDescent - 1,
+                                      LColor::background);
+               }
+               frame_is_visible = false;
+       }
+}
+
+
 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
 {
-       if (reinit) {  // && (need_update != CURSOR)) {
-               need_update = INIT;
+       if (reinit) {
+               need_update |= INIT;
                resizeLyXText(bv);
                if (owner())
                        owner()->update(bv, font, true);
@@ -461,46 +433,39 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
                inset_y = cy(bv) + drawTextYOffset;
                the_locking_inset->update(bv, font, reinit);
        }
+#if 0
        if (need_update == INIT) {
                resizeLyXText(bv);
-               need_update = FULL;
+               need_update |= FULL;
        }
+#endif
        int oldw = insetWidth;
-#if 1
        insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
-       // max(textWidth(bv->painter()),
-       // static_cast<int>(TEXT(bv)->width) + drawTextXOffset) +
-       // (2 * TEXT_TO_INSET_OFFSET);
-#else
-       insetWidth = textWidth(bv);
-       if (insetWidth < 0)
-               insetWidth = static_cast<int>(TEXT(bv)->width);
-#endif
        if (oldw != insetWidth) {
-//         printf("TW(%p): %d-%d-%d-%d\n",this,insetWidth, oldw,
-//                textWidth(bv->painter()),static_cast<int>(TEXT(bv)->width));
                resizeLyXText(bv);
-               need_update = FULL;
-               update(bv, font, reinit);
+               need_update |= FULL;
+//             update(bv, font, reinit);
                return;
        }
-       if ((need_update==CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
+       if ((need_update&CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
                the_locking_inset)
        {
                TEXT(bv)->UpdateInset(bv, the_locking_inset);
        }
        
        if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
-               need_update = FULL;
-
+               need_update |= FULL;
+#if 0
        int y_temp = 0;
        Row * row = TEXT(bv)->GetRowNearY(y_temp);
        insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
        insetDescent = TEXT(bv)->height - row->ascent_of_text() +
                TEXT_TO_INSET_OFFSET;
+#endif
 }
 
-void InsetText::SetUpdateStatus(BufferView * bv, int what)
+
+void InsetText::SetUpdateStatus(BufferView * bv, int what) const
 {
        need_update |= what;
        if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
@@ -513,6 +478,7 @@ void InsetText::SetUpdateStatus(BufferView * bv, int what)
                TEXT(bv)->ClearSelection(bv);
 }
 
+
 void InsetText::UpdateLocal(BufferView * bv, int what, bool mark_dirty)
 {
        TEXT(bv)->FullRebreak(bv);
@@ -549,22 +515,18 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
        inset_boundary = false;
        inset_par = 0;
        old_par = 0;
-       if (!checkAndActivateInset(bv, x, y, button))
-               TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
-                                                                                  y+insetAscent);
+       int tmp_y = (y < 0)?0:y;
+       if (!checkAndActivateInset(bv, x, tmp_y, button))
+               TEXT(bv)->SetCursorFromCoordinates(bv, x - drawTextXOffset,
+                                                  y + insetAscent);
        TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        bv->text->FinishUndo();
        ShowInsetCursor(bv);
-       UpdateLocal(bv, FULL, false);
+       UpdateLocal(bv, CURSOR, false);
 
        // If the inset is empty set the language of the current font to the
        // language to the surronding text.
-#ifndef NEW_INSETS
-       if (par->Last() == 0 && !par->next_)
-#else
-       if (par->size() == 0 && !par->next())
-#endif
-       {
+       if (par->size() == 0 && !par->next()) {
                LyXFont font(LyXFont::ALL_IGNORE);
                font.setLanguage(bv->getParentLanguage(this));
                SetFont(bv, font, false);
@@ -584,7 +546,7 @@ void InsetText::InsetUnlock(BufferView * bv)
        UpdateLocal(bv, CLEAR_FRAME|CURSOR, false);
        if (owner())
                bv->owner()->setLayout(owner()->getLyXText(bv)
-                                                          ->cursor.par()->GetLayout());
+                                      ->cursor.par()->GetLayout());
        else
                bv->owner()->setLayout(bv->text->cursor.par()->GetLayout());
 }
@@ -592,7 +554,8 @@ void InsetText::InsetUnlock(BufferView * bv)
 
 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
 {
-       lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
+       lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
+                             << inset << "): ";
        if (!inset)
                return false;
        if (inset == cpar(bv)->GetInset(cpos(bv))) {
@@ -629,7 +592,7 @@ bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
 
 
 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
-                                                                  bool lr)
+                                  bool lr)
 {
        if (!the_locking_inset)
                return false;
@@ -640,7 +603,10 @@ bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                if (lr)
                        moveRight(bv, false);
                old_par = 0; // force layout setting
-               UpdateLocal(bv, CURSOR_PAR, false);
+               if (scroll())
+                       scroll(bv, 0.0F);
+               else
+                       UpdateLocal(bv, CURSOR, false);
                return true;
        }
        return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
@@ -707,7 +673,8 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
                        inset_par = cpar(bv);
                        inset_boundary = cboundary(bv);
                        the_locking_inset = uinset;
-                       uinset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
+                       uinset->InsetButtonPress(bv, x - inset_x, y - inset_y,
+                                                button);
                        uinset->Edit(bv, x - inset_x, y - inset_y, 0);
                        if (the_locking_inset)
                                UpdateLocal(bv, CURSOR, false);
@@ -715,14 +682,14 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
                        return;
                }
        }
-       if (!inset && (button == 2)) {
+       if (!inset) { // && (button == 2)) {
                bool paste_internally = false;
                if ((button == 2) && TEXT(bv)->selection) {
                        LocalDispatch(bv, LFUN_COPY, "");
                        paste_internally = true;
                }
                TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
-                                                                                  y + insetAscent);
+                                                  y + insetAscent);
                TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
                UpdateLocal(bv, CURSOR, false);
                bv->owner()->setLayout(cpar(bv)->GetLayout());
@@ -734,7 +701,8 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
                        if (paste_internally)
                                LocalDispatch(bv, LFUN_PASTE, "");
                        else
-                               LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
+                               LocalDispatch(bv, LFUN_PASTESELECTION,
+                                             "paragraph");
                }
        }
        ShowInsetCursor(bv);
@@ -748,18 +716,23 @@ void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
 
        if (the_locking_inset) {
                the_locking_inset->InsetButtonRelease(bv,
-                                                                                         x - inset_x, y - inset_y,
-                                                                                         button);
+                                                     x - inset_x, y - inset_y,
+                                                     button);
        } else {
                if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
                        inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
                        if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
-                               inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
+                               inset->InsetButtonRelease(bv,
+                                                         x - inset_x,
+                                                         y - inset_y, button);
                        } else {
                                inset_x = cx(bv) - top_x + drawTextXOffset;
                                inset_y = cy(bv) + drawTextYOffset;
-                               inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
-                               inset->Edit(bv, x - inset_x, y - inset_y, button);
+                               inset->InsetButtonRelease(bv,
+                                                         x - inset_x,
+                                                         y - inset_y, button);
+                               inset->Edit(bv,
+                                           x - inset_x, y - inset_y, button);
                        }
                        UpdateLocal(bv, CURSOR_PAR, false);
                }
@@ -774,12 +747,12 @@ void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
                return;
        if (the_locking_inset) {
                the_locking_inset->InsetMotionNotify(bv, x - inset_x,
-                                                                                        y - inset_y,state);
+                                                    y - inset_y,state);
                return;
        }
        HideInsetCursor(bv);
-       TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
-                                                                          y+insetAscent);
+       TEXT(bv)->SetCursorFromCoordinates(bv, x - drawTextXOffset,
+                                          y + insetAscent);
        TEXT(bv)->SetSelection(bv);
        if (TEXT(bv)->toggle_cursor.par()!=TEXT(bv)->toggle_end_cursor.par() ||
                TEXT(bv)->toggle_cursor.pos()!=TEXT(bv)->toggle_end_cursor.pos())
@@ -799,7 +772,7 @@ void InsetText::InsetKeyPress(XKeyEvent * xke)
 
 UpdatableInset::RESULT
 InsetText::LocalDispatch(BufferView * bv,
-                                                kb_action action, string const & arg)
+                        kb_action action, string const & arg)
 {
        no_selection = false;
        UpdatableInset::RESULT
@@ -808,7 +781,7 @@ InsetText::LocalDispatch(BufferView * bv,
                return DISPATCHED;
        }
 
-       result=DISPATCHED;
+       result = DISPATCHED;
        if ((action < 0) && arg.empty())
                return FINISHED;
 
@@ -861,14 +834,8 @@ InsetText::LocalDispatch(BufferView * bv,
                         * true (on). */
 
                        bv->text->SetUndo(bv->buffer(), Undo::INSERT,
-#ifndef NEW_INSETS
-                                                         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                         bv->text->cursor.par()->previous(),
-                                                         bv->text->cursor.par()->next()
-#endif
-                                                         );
+                                         bv->text->cursor.par()->previous(),
+                                         bv->text->cursor.par()->next());
                        bv->setState();
                        if (lyxrc.auto_region_delete) {
                                if (TEXT(bv)->selection){
@@ -892,7 +859,7 @@ InsetText::LocalDispatch(BufferView * bv,
                UpdateLocal(bv, CURSOR_PAR, true);
                result=DISPATCHED_NOUPDATE;
                break;
-               // --- Cursor Movements ---------------------------------------------
+               // --- Cursor Movements -----------------------------------
        case LFUN_RIGHTSEL:
                bv->text->FinishUndo();
                moveRight(bv, false, true);
@@ -948,14 +915,8 @@ InsetText::LocalDispatch(BufferView * bv,
                break;
        case LFUN_BACKSPACE:
                bv->text->SetUndo(bv->buffer(), Undo::DELETE,
-#ifndef NEW_INSETS
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                 bv->text->cursor.par()->previous(),
-                                                 bv->text->cursor.par()->next()
-#endif
-                                                 );
+                                 bv->text->cursor.par()->previous(),
+                                 bv->text->cursor.par()->next());
                if (TEXT(bv)->selection)
                        TEXT(bv)->CutSelection(bv);
                else
@@ -964,14 +925,8 @@ InsetText::LocalDispatch(BufferView * bv,
                break;
        case LFUN_DELETE:
                bv->text->SetUndo(bv->buffer(), Undo::DELETE,
-#ifndef NEW_INSETS
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                 bv->text->cursor.par()->previous(),
-                                                 bv->text->cursor.par()->next()
-#endif
-                                                 );
+                                 bv->text->cursor.par()->previous(),
+                                 bv->text->cursor.par()->next());
                if (TEXT(bv)->selection)
                        TEXT(bv)->CutSelection(bv);
                else
@@ -980,14 +935,8 @@ InsetText::LocalDispatch(BufferView * bv,
                break;
        case LFUN_CUT:
                bv->text->SetUndo(bv->buffer(), Undo::DELETE,
-#ifndef NEW_INSETS
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                 bv->text->cursor.par()->previous(),
-                                                 bv->text->cursor.par()->next()
-#endif
-                                                 );
+                                 bv->text->cursor.par()->previous(),
+                                 bv->text->cursor.par()->next());
                TEXT(bv)->CutSelection(bv);
                UpdateLocal(bv, CURSOR_PAR, true);
                break;
@@ -998,7 +947,7 @@ InsetText::LocalDispatch(BufferView * bv,
                break;
        case LFUN_PASTESELECTION:
        {
-               string clip(bv->workarea()->getClipboard());
+               string clip(bv->getClipboard());
        
                if (clip.empty())
                        break;
@@ -1022,14 +971,8 @@ InsetText::LocalDispatch(BufferView * bv,
                        }
                }
                bv->text->SetUndo(bv->buffer(), Undo::INSERT,
-#ifndef NEW_INSETS
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                 bv->text->cursor.par()->previous(),
-                                                 bv->text->cursor.par()->next()
-#endif
-                                                 );
+                                 bv->text->cursor.par()->previous(),
+                                 bv->text->cursor.par()->next());
                TEXT(bv)->PasteSelection(bv);
                UpdateLocal(bv, CURSOR_PAR, true);
                break;
@@ -1049,14 +992,8 @@ InsetText::LocalDispatch(BufferView * bv,
                if (!autoBreakRows)
                        return DISPATCHED;
                bv->text->SetUndo(bv->buffer(), Undo::INSERT,
-#ifndef NEW_INSETS
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                 bv->text->cursor.par()->previous(),
-                                                 bv->text->cursor.par()->next()
-#endif
-                                                 );
+                                 bv->text->cursor.par()->previous(),
+                                 bv->text->cursor.par()->next());
                TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
                UpdateLocal(bv, CURSOR_PAR, true);
                break;
@@ -1082,9 +1019,8 @@ InsetText::LocalDispatch(BufferView * bv,
 
                        // see if we found the layout number:
                        if (!layout.first) {
-                               string msg = string(N_("Layout ")) + arg + N_(" not known");
-
-                               bv->owner()->getMiniBuffer()->Set(msg);
+                               string const msg = string(N_("Layout ")) + arg + N_(" not known");
+                               bv->owner()->getLyXFunc()->Dispatch(LFUN_MESSAGE, msg);
                                break;
                        }
 
@@ -1155,12 +1091,7 @@ InsetText::LocalDispatch(BufferView * bv,
 
        /// If the action has deleted all text in the inset, we need to change the
        // language to the language to the surronding text.
-#ifndef NEW_INSETS
-       if (par->Last() == 0 && !par->next_)
-#else
-       if (par->size() == 0 && !par->next())
-#endif
-       {
+       if (par->size() == 0 && !par->next()) {
                LyXFont font(LyXFont::ALL_IGNORE);
                font.setLanguage(bv->getParentLanguage(this));
                SetFont(bv, font, false);
@@ -1192,11 +1123,7 @@ int InsetText::Ascii(Buffer const * buf, ostream & os, int linelen) const
                tmp = buf->asciiParagraph(p, linelen);
                lines += countChar(tmp, '\n');
                os << tmp;
-#ifndef NEW_INSETS
                p = p->next();
-#else
-               p = p->next();
-#endif
        }
        return lines;
 }
@@ -1211,11 +1138,7 @@ int InsetText::DocBook(Buffer const * buf, ostream & os) const
        string tmp;
        while (p) {
                buf->SimpleDocBookOnePar(os,tmp,p,desc,0);
-#ifndef NEW_INSETS
-               p = p->next_;
-#else
                p = p->next();
-#endif
        }
        
        return lines;
@@ -1227,11 +1150,7 @@ void InsetText::Validate(LaTeXFeatures & features) const
        LyXParagraph * p = par;
        while(p) {
                p->validate(features);
-#ifndef NEW_INSETS
-               p = p->next_;
-#else
                p = p->next();
-#endif
        }
 }
 
@@ -1239,7 +1158,7 @@ void InsetText::Validate(LaTeXFeatures & features) const
 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
 {
        if (textclasslist.Style(buf->params.textclass,
-                                                       p->GetLayout()).labeltype != LABEL_MANUAL)
+                               p->GetLayout()).labeltype != LABEL_MANUAL)
                return 0;
        else
                return p->BeginningOfMainBody();
@@ -1247,7 +1166,7 @@ int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
 
 
 void InsetText::GetCursorPos(BufferView * bv,
-                                                        int & x, int & y) const
+                            int & x, int & y) const
 {
        x = cx(bv);
        y = cy(bv);
@@ -1336,13 +1255,9 @@ InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
 
 UpdatableInset::RESULT
 InsetText::moveRightIntern(BufferView * bv, bool behind, 
-                                                  bool activate_inset, bool selecting)
+                          bool activate_inset, bool selecting)
 {
-#ifndef NEW_INSETS
-       if (!cpar(bv)->next_ && (cpos(bv) >= cpar(bv)->Last()))
-#else
        if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
-#endif
                return FINISHED;
        if (activate_inset && checkAndActivateInset(bv, behind))
                return DISPATCHED;
@@ -1355,13 +1270,9 @@ InsetText::moveRightIntern(BufferView * bv, bool behind,
 
 UpdatableInset::RESULT
 InsetText::moveLeftIntern(BufferView * bv, bool behind,
-                                                 bool activate_inset, bool selecting)
+                         bool activate_inset, bool selecting)
 {
-#ifndef NEW_INSETS
-       if (!cpar(bv)->previous_ && (cpos(bv) <= 0))
-#else
        if (!cpar(bv)->previous() && (cpos(bv) <= 0))
-#endif
                return FINISHED;
        TEXT(bv)->CursorLeft(bv);
        if (!selecting)
@@ -1400,14 +1311,8 @@ bool InsetText::InsertInset(BufferView * bv, Inset * inset)
                return false;
        }
        bv->text->SetUndo(bv->buffer(), Undo::INSERT,
-#ifndef NEW_INSETS
-                                         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                         bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                         bv->text->cursor.par()->previous(),
-                                         bv->text->cursor.par()->next()
-#endif
-                                         );
+                         bv->text->cursor.par()->previous(),
+                         bv->text->cursor.par()->next());
        inset->setOwner(this);
        HideInsetCursor(bv);
        TEXT(bv)->InsertInset(bv, inset);
@@ -1469,14 +1374,8 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
 {
        if (TEXT(bv)->selection) {
                bv->text->SetUndo(bv->buffer(), Undo::EDIT,
-#ifndef NEW_INSETS
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous_,
-                                                 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next_
-#else
-                                                 bv->text->cursor.par()->previous(),
-                                                 bv->text->cursor.par()->next()
-#endif
-                                                 );
+                                 bv->text->cursor.par()->previous(),
+                                 bv->text->cursor.par()->next());
        }
        TEXT(bv)->SetFont(bv, font, toggleall);
        bv->fitCursor(TEXT(bv));
@@ -1507,7 +1406,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
                inset->Edit(bv, x, y, 0);
                if (!the_locking_inset)
                        return false;
-               UpdateLocal(bv, CURSOR_PAR, false);
+               UpdateLocal(bv, CURSOR, false);
                return true;
        }
        return false;
@@ -1515,7 +1414,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
 
 
 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
-                                                                         int button)
+                                     int button)
 {
        int dummyx, dummyy;
 
@@ -1533,7 +1432,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
                inset->Edit(bv, x - inset_x, y - inset_y, button);
                if (!the_locking_inset)
                        return false;
-               UpdateLocal(bv, CURSOR_PAR, false);
+               UpdateLocal(bv, CURSOR, false);
                return true;
        }
        return false;
@@ -1565,49 +1464,23 @@ void InsetText::SetParagraphData(LyXParagraph * p)
                (*cit).second = 0;
        }
 
-#ifndef NEW_INSETS
-       LyXParagraph * np;
-       if (par) {
-               np = par->next_;
+       while (par) {
+               LyXParagraph * tmp = par->next();
                delete par;
-               while (np) {
-                       par = np;
-                       np = np->next_;
-                       delete par;
-               }
+               par = tmp;
        }
-       par = p->Clone();
-       par->SetInsetOwner(this);
-       np = par;
-       while (p->next_) {
-               p = p->next_;
-               np->next(p->Clone());
-               np->next_->previous(np);
-               np = np->next_;
-               np->SetInsetOwner(this);
-       }
-#else
-       LyXParagraph * np;
-       if (par) {
-               np = par->next();
-               delete par;
-               while(np) {
-                       par = np;
-                       np = np->next();
-                       delete par;
-               }
-       }
-       par = p->Clone();
+
+       par = new LyXParagraph(*p);
        par->SetInsetOwner(this);
-       np = par;
-       while(p->next()) {
+       LyXParagraph * np = par;
+       while (p->next()) {
                p = p->next();
-               np->next(p->Clone());
+               np->next(new LyXParagraph(*p));
                np->next()->previous(np);
                np = np->next();
                np->SetInsetOwner(this);
        }
-#endif
+
        need_update = INIT;
 }
 
@@ -1616,7 +1489,7 @@ void InsetText::SetText(string const & data)
 {
        clear();
        LyXFont font(LyXFont::ALL_SANE);
-       for(unsigned int i=0; i < data.length(); ++i)
+       for (unsigned int i=0; i < data.length(); ++i)
                par->InsertChar(i, data[i], font);
 }
 
@@ -1634,8 +1507,8 @@ void InsetText::SetAutoBreakRows(bool flag)
 
 void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how)
 {
-       if (how != drawFrame) {
-               drawFrame = how;
+       if (how != drawFrame_) {
+               drawFrame_ = how;
                if (bv)
                        UpdateLocal(bv, DRAW_FRAME, false);
        }
@@ -1658,7 +1531,8 @@ int InsetText::cx(BufferView * bv) const
        int x = text->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
        if (the_locking_inset) {
                LyXFont font = text->GetFont(bv->buffer(),
-                                                                        text->cursor.par(), text->cursor.pos());
+                                            text->cursor.par(),
+                                            text->cursor.pos());
                if (font.isVisibleRightToLeft())
                        x -= the_locking_inset->width(bv, font);
        }
@@ -1696,7 +1570,8 @@ Row * InsetText::crow(BufferView * bv) const
 }
 
 
-LyXText * InsetText::getLyXText(BufferView const * lbv, bool const recursive) const
+LyXText * InsetText::getLyXText(BufferView const * lbv,
+                               bool const recursive) const
 {
        // Super UGLY! (Lgb)
        BufferView * bv = const_cast<BufferView *>(lbv);
@@ -1727,26 +1602,16 @@ void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
        if (recursive) {
                /// then remove all LyXText in text-insets
                LyXParagraph * p = par;
-#ifndef NEW_INSETS
-               for (; p; p = p->next_) {
-                       p->deleteInsetsLyXText(bv);
-               }
-#else
                for (; p; p = p->next()) {
                        p->deleteInsetsLyXText(bv);
                }
-#endif
        }
 }
 
 
 void InsetText::resizeLyXText(BufferView * bv) const
 {
-#ifndef NEW_INSETS
-       if (!par->next_ && !par->size()) // resize not neccessary!
-#else
        if (!par->next() && !par->size()) // resize not neccessary!
-#endif
                return;
        if ((cache.find(bv) == cache.end()) || !cache[bv])
                return;
@@ -1786,10 +1651,11 @@ void InsetText::resizeLyXText(BufferView * bv) const
                 * Mechanism when setting the cursor */
                TEXT(bv)->mark_set = mark_set;
                if (selection) {
-                       TEXT(bv)->SetCursor(bv, selstartpar, selstartpos,true, 
-                                                               selstartboundary);
+                       TEXT(bv)->SetCursor(bv, selstartpar, selstartpos,
+                                           true, selstartboundary);
                        TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
-                       TEXT(bv)->SetCursor(bv, selendpar, selendpos, true, selendboundary);
+                       TEXT(bv)->SetCursor(bv, selendpar, selendpos,
+                                           true, selendboundary);
                        TEXT(bv)->SetSelection(bv);
                        TEXT(bv)->SetCursor(bv, lpar, pos);
                } else {
@@ -1807,15 +1673,9 @@ void InsetText::resizeLyXText(BufferView * bv) const
                /// then resize all LyXText in text-insets
                inset_x = cx(bv) - top_x + drawTextXOffset;
                inset_y = cy(bv) + drawTextYOffset;
-#ifndef NEW_INSETS
-               for (LyXParagraph * p = par; p; p = p->next_) {
-                       p->resizeInsetsLyXText(bv);
-               }
-#else
                for (LyXParagraph * p = par; p; p = p->next()) {
                        p->resizeInsetsLyXText(bv);
                }
-#endif
        }
        need_update = FULL;
 }
@@ -1823,15 +1683,38 @@ void InsetText::resizeLyXText(BufferView * bv) const
 
 void InsetText::removeNewlines()
 {
-#ifndef NEW_INSETS
-       for (LyXParagraph * p = par; p; p = p->next_) {
-               for (int i = 0; i < p->Last(); ++i) {
-#else
        for (LyXParagraph * p = par; p; p = p->next()) {
                for (int i = 0; i < p->size(); ++i) {
-#endif
                        if (p->GetChar(i) == LyXParagraph::META_NEWLINE)
                                p->Erase(i);
                }
        }
 }
+
+bool InsetText::nodraw() const
+{
+       if (the_locking_inset)
+               return the_locking_inset->nodraw();
+       return UpdatableInset::nodraw();
+}
+
+int InsetText::scroll(bool recursive) const
+{
+       int sx = UpdatableInset::scroll(false);
+
+       if (recursive && the_locking_inset)
+               sx += the_locking_inset->scroll(recursive);
+
+       return sx;
+}
+
+bool InsetText::doClearArea() const
+{
+       return !locked || (need_update & (FULL|INIT));
+}
+/* Emacs:
+ * Local variables:
+ * tab-width: 4
+ * End:
+ * vi:set tabstop=4:
+ */