]> 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 33ffcfa753f1de780fe19a34ed1e2dc1d2670c78..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;
@@ -91,9 +92,6 @@ 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;
@@ -124,21 +122,12 @@ InsetText::~InsetText()
                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
+
        while (par) {
                LyXParagraph * tmp = par->next();
                delete par;
                par = tmp;
        }
-#endif
 }
 
 
@@ -146,25 +135,16 @@ 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
+
        while (par) {
                LyXParagraph * tmp = par->next();
                delete par;
                par = tmp;
        }
-#endif
        par = new LyXParagraph;
 }
 
@@ -195,35 +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
-       while (par) {
-               LyXParagraph * tmp = par->next();
-               delete par;
-               par = tmp;
-       }
-#endif
-       par = new LyXParagraph;
+       clear();
+       
        while (lex.IsOK()) {
                lex.nextToken();
                token = lex.GetString();
@@ -233,12 +188,7 @@ void InsetText::Read(Buffer const * buf, LyXLex & lex)
                        break;
                if (const_cast<Buffer*>(buf)->
                        parseSingleLyXformat2Token(lex, par, return_par,
-                                                  token, pos, depth, font
-#ifndef NEW_INSETS
-                                                  , footnoteflag, footnotekind
-#endif
-                               ))
-               {
+                                                  token, pos, depth, font)) {
                        // the_end read this should NEVER happen
                        lex.printError("\\the_end read in inset! Error in document!");
                        return;
@@ -249,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") {
@@ -322,7 +268,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        UpdatableInset::draw(bv, f, baseline, x, cleared);
 #else
        if (!owner())
-               x += (float)scroll();
+               x += static_cast<float>(scroll());
 #endif
        // update insetWidth and insetHeight with dummy calls
        (void)ascent(bv, f);
@@ -384,8 +330,11 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        }
        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 contest (Jug)!
+#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);
@@ -566,7 +515,8 @@ 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))
+       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;
@@ -576,12 +526,7 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
 
        // 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);
@@ -737,7 +682,7 @@ 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, "");
@@ -889,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()->next());
                        bv->setState();
                        if (lyxrc.auto_region_delete) {
                                if (TEXT(bv)->selection){
@@ -976,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()->next());
                if (TEXT(bv)->selection)
                        TEXT(bv)->CutSelection(bv);
                else
@@ -992,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()->next());
                if (TEXT(bv)->selection)
                        TEXT(bv)->CutSelection(bv);
                else
@@ -1008,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()->next());
                TEXT(bv)->CutSelection(bv);
                UpdateLocal(bv, CURSOR_PAR, true);
                break;
@@ -1026,7 +947,7 @@ InsetText::LocalDispatch(BufferView * bv,
                break;
        case LFUN_PASTESELECTION:
        {
-               string clip(bv->workarea()->getClipboard());
+               string clip(bv->getClipboard());
        
                if (clip.empty())
                        break;
@@ -1050,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()->next());
                TEXT(bv)->PasteSelection(bv);
                UpdateLocal(bv, CURSOR_PAR, true);
                break;
@@ -1077,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()->next());
                TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
                UpdateLocal(bv, CURSOR_PAR, true);
                break;
@@ -1110,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;
                        }
 
@@ -1183,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);
@@ -1220,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;
 }
@@ -1239,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;
@@ -1255,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
        }
 }
 
@@ -1366,11 +1257,7 @@ UpdatableInset::RESULT
 InsetText::moveRightIntern(BufferView * bv, bool behind, 
                           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;
@@ -1385,11 +1272,7 @@ UpdatableInset::RESULT
 InsetText::moveLeftIntern(BufferView * bv, bool behind,
                          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)
@@ -1428,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()->next());
        inset->setOwner(this);
        HideInsetCursor(bv);
        TEXT(bv)->InsertInset(bv, inset);
@@ -1497,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()->next());
        }
        TEXT(bv)->SetFont(bv, font, toggleall);
        bv->fitCursor(TEXT(bv));
@@ -1593,45 +1464,23 @@ void InsetText::SetParagraphData(LyXParagraph * p)
                (*cit).second = 0;
        }
 
-#ifndef NEW_INSETS
-       LyXParagraph * np;
-       if (par) {
-               np = par->next_;
-               delete par;
-               while (np) {
-                       par = np;
-                       np = np->next_;
-                       delete par;
-               }
-       }
-       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
        while (par) {
                LyXParagraph * tmp = par->next();
                delete par;
                par = tmp;
        }
 
-       par = p->Clone();
+       par = new LyXParagraph(*p);
        par->SetInsetOwner(this);
        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;
 }
 
@@ -1753,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;
@@ -1834,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;
 }
@@ -1850,13 +1683,8 @@ 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);
                }