]> git.lyx.org Git - lyx.git/commitdiff
the Paragraph::inInset() changes
authorAndré Pönitz <poenitz@gmx.net>
Thu, 8 Apr 2004 15:03:33 +0000 (15:03 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 8 Apr 2004 15:03:33 +0000 (15:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8632 a592a061-630c-0410-9148-cb99ea01b6c8

28 files changed:
src/Bidi.C
src/ChangeLog
src/CutAndPaste.C
src/ParagraphParameters.C
src/buffer.C
src/cursor.C
src/cursor.h
src/frontends/qt2/QGraphics.C
src/insets/insetbase.C
src/insets/insetbranch.C
src/insets/insetexternal.C
src/insets/insetfloat.C
src/insets/insetgraphics.C
src/insets/insetinclude.C
src/insets/insettabular.C
src/insets/insettext.C
src/insets/insettext.h
src/mathed/math_mathmlstream.C
src/mathed/math_mathmlstream.h
src/mathed/math_mboxinset.C
src/mathed/math_nestinset.C
src/output_latex.C
src/outputparams.h
src/paragraph.C
src/paragraph.h
src/text.C
src/text2.C
src/text3.C

index e469270558fbef7b9f4be8215fb2de9f603257d8..db4775449bd0a7f6952f5032ea55e13f726c25ee 100644 (file)
@@ -17,7 +17,6 @@
 #include "lyxrc.h"
 #include "paragraph.h"
 
-#include "insets/updatableinset.h"
 
 using lyx::pos_type;
 
@@ -60,8 +59,7 @@ void Bidi::computeTables(Paragraph const & par,
                return;
        }
 
-       InsetOld * inset = par.inInset();
-       if (inset && inset->lyxCode() == InsetOld::ERT_CODE) {
+       if (par.ownerCode() == InsetBase::ERT_CODE) {
                start_ = -1;
                return;
        }
index ac5df78442258d580ce54621e9db9749866a899f..967af69f7f181536b7d38b7c0eaf8b8a45e19847 100644 (file)
 
        * lyxfunc.C (dispatch): output lyxrc.write("preferences", false).
 
+2004-04-07  André Pönitz  <poenitz@gmx.net>
+
+       * cursor.[Ch] (selClear, adjust): remove math
+
+       * cursor_slice.C: more agressive assert
+
+       * lyxfunc.C:
+       * BufferView_pimpl.C: rework mouse event dispatch 
+
+       * dociterator.C:
+       * paragraph.C:
+       * text2.C:
+       * text3.C: adjust
+
 2004-04-05  André Pönitz  <poenitz@gmx.net>
 
        * cursor.[Ch] (valign, halign...): remove unneeded functions
index 8202bb0ed427c2db3f6a12695c9bb30f96907e99..0cd4a1a33418087d0b6e78f120d94efcdca53b42 100644 (file)
@@ -416,7 +416,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut)
 
        int endpos = cur.selEnd().pos();
 
-       BufferParams const & bufparams = cur.bv().buffer()->params();
+       BufferParams const & bufparams = cur.buffer().params();
        boost::tie(endpit, endpos) = realcut ?
                cutSelection(bufparams,
                                          text->paragraphs(),
@@ -470,7 +470,7 @@ void copySelection(LCursor & cur)
                ++pos;
 
        copySelection(pars, par, cur.selEnd().par(),
-               pos, cur.selEnd().pos(), cur.bv().buffer()->params().textclass);
+               pos, cur.selEnd().pos(), cur.buffer().params().textclass);
 }
 
 
@@ -490,13 +490,13 @@ void pasteSelection(LCursor & cur, size_t sel_index)
        ErrorList el;
 
        boost::tie(ppp, endpit) =
-               pasteSelection(*cur.bv().buffer(),
+               pasteSelection(cur.buffer(),
                                            text->paragraphs(),
                                            cur.par(), cur.pos(),
-                                           cur.bv().buffer()->params().textclass,
+                                           cur.buffer().params().textclass,
                                            sel_index, el);
-       bufferErrors(*cur.bv().buffer(), el);
-       text->bv()->showErrorList(_("Paste"));
+       bufferErrors(cur.buffer(), el);
+       cur.bv().showErrorList(_("Paste"));
 
        text->redoParagraphs(cur.par(), endpit);
 
@@ -531,7 +531,7 @@ void replaceSelectionWithString(LCursor & cur, string const & str)
        // Get font setting before we cut
        pos_type pos = cur.selEnd().pos();
        LyXFont const font = text->getPar(cur.selBegin().par()).
-               getFontSettings(cur.bv().buffer()->params(), cur.selBegin().pos());
+               getFontSettings(cur.buffer().params(), cur.selBegin().pos());
 
        // Insert the new string
        string::const_iterator cit = str.begin();
index 9f7343d5a1d8c805e2e0165a8dc63cf3853abf89..7f4ecfcdb9afb7496f54b349b905aa1e390e0122 100644 (file)
@@ -281,8 +281,8 @@ void params2string(Paragraph const & par, string & data)
        /// set default alignment
        os << "\\aligndefault " << layout->align << '\n';
 
-       /// is paragraph in inset
-       os << "\\ininset " << (par.inInset()?1:0) << '\n';
+       /// paragraph is always in inset. This is redundant.
+       os << "\\ininset " << 1 << '\n';
 
        data = os.str();
 }
index 293b134b48edfc268b783397a23e69d33d073bd5..d16d74ed22177300e34627147129d731f324a29a 100644 (file)
@@ -456,8 +456,7 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
        pars[par].checkInsertChar(font);
        // insert the string, don't insert doublespace
        bool space_inserted = true;
-       bool autobreakrows = !pars[par].inInset() ||
-               static_cast<InsetText *>(pars[par].inInset())->getAutoBreakRows();
+       bool autobreakrows = pars[par].autoBreakRows();
        for (string::const_iterator cit = str.begin();
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
index 4642a2ee3aee666f998e813c880cea116c285866..8ca2bd906c45fb6530d69bad0b77d5bb7e78234d 100644 (file)
@@ -172,10 +172,19 @@ bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
 
 BufferView & LCursor::bv() const
 {
+       BOOST_ASSERT(bv_);
        return *bv_;
 }
 
 
+Buffer & LCursor::buffer() const
+{
+       BOOST_ASSERT(bv_);
+       BOOST_ASSERT(bv_->buffer());
+       return *bv_->buffer();
+}
+
+
 void LCursor::pop()
 {
        BOOST_ASSERT(size() >= 1);
index 6a60cbcd128ef2303e35a168a0fa9cf1be1d77ea..16ae747aa568469ceff203278ab2bf5eaa548064 100644 (file)
@@ -18,6 +18,7 @@
 #include <iosfwd>
 #include <vector>
 
+class Buffer;
 class BufferView;
 class FuncStatus;
 class FuncRequest;
@@ -146,6 +147,8 @@ public:
        void resetAnchor();
        /// access to owning BufferView
        BufferView & bv() const;
+       /// access to owning Buffer
+       Buffer & buffer() const;
        /// get some interesting description of top position
        void info(std::ostream & os) const;
        /// are we in math mode (2), text mode (1) or unsure (0)?
@@ -155,8 +158,6 @@ public:
        void reset(InsetBase &);
        /// for spellchecking
        void replaceWord(std::string const & replacestring);
-       /// update our view
-       void update();
        /// the event was not (yet) dispatched
        void undispatched();
        /// the event was already dispatched
index 7b691f6cff5b78514e3da4a7d2d045c3cbaaff8c..57613355b90a9286eef76da13556397223671be2 100644 (file)
@@ -349,11 +349,11 @@ void QGraphics::apply()
        if (!dialog_->displayCB->isChecked())
                igp.display = lyx::graphics::NoDisplay;
 
-       string value(fromqstr(dialog_->width->text()));
+       string value = fromqstr(dialog_->width->text());
        if (dialog_->widthUnit->currentItem() > 0) {
                // width/height combination
-               int const unitNo = getUnitNo(unit_name_gui,
-                       fromqstr(dialog_->widthUnit->currentText()));
+               QString const text = dialog_->widthUnit->currentText();
+               int const unitNo = getUnitNo(unit_name_gui, fromqstr(text));
                igp.width = LyXLength(value + unit_name_ltx[unitNo]);
                igp.scale = 0.0;
        } else {
@@ -362,8 +362,8 @@ void QGraphics::apply()
                igp.width = LyXLength();
        }
        value = fromqstr(dialog_->height->text());
-       int const unitNo = getUnitNo(unit_name_gui,
-               fromqstr(dialog_->heightUnit->currentText()));
+       QString text = dialog_->heightUnit->currentText();
+       int const unitNo = getUnitNo(unit_name_gui, fromqstr(text));
        igp.height = LyXLength(value + unit_name_ltx[unitNo]);
 
        igp.keepAspectRatio = dialog_->aspectratio->isChecked();
@@ -373,6 +373,7 @@ void QGraphics::apply()
        igp.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
 
        igp.rotateAngle = strToDbl(fromqstr(dialog_->angle->text()));
+#warning Guess what happens if the user enters '1e30' here?
        while (igp.rotateAngle < -360.0)
                igp.rotateAngle += 360.0;
        while (igp.rotateAngle >  360.0)
index 45d957ab341b722761174af89453a56ea94509d0..d08c3459c2c11e4165817ad87543157a0c0f76a3 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <map>
 
+
 namespace {
 
 struct InsetName {
@@ -36,8 +37,10 @@ struct InsetName {
        InsetBase::Code code;
 };
 
+
 typedef std::map<std::string, InsetBase::Code> TranslatorMap;
 
+
 TranslatorMap const build_translator()
 {
        InsetName const insetnames[] = {
@@ -285,6 +288,11 @@ bool InsetBase::editing(BufferView * bv) const
 
 bool InsetBase::covers(int x, int y) const
 {
+       //lyxerr << "InsetBase::covers, x: " << x << " y: " << y 
+       //      << " xo: " << xo() << " yo: " << yo()
+       //      << " x1: " << xo() << " x2: " << xo() + width()
+       //      << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
+       //      << std::endl;
        return x >= xo()
                        && x <= xo() + width()
                        && y >= yo() - ascent()
index a8909d5a07dedfc672bf1f4d9a57ffe40c0d979a..ac64ed5dc3ed651cb1abd40730cae7ff03112d82 100644 (file)
@@ -13,7 +13,6 @@
 #include "insetbranch.h"
 
 #include "buffer.h"
-#include "BufferView.h"
 #include "bufferparams.h"
 #include "BranchList.h"
 #include "cursor.h"
@@ -162,7 +161,7 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                } else if (cmd.argument == "assign"
                           || cmd.argument.empty()) {
                        BranchList const & branchlist =
-                               cur.bv().buffer()->params().branchlist();
+                               cur.buffer().params().branchlist();
                        if (isBranchSelected(branchlist)) {
                                if (status() != Open)
                                        setStatus(Open);
index d4e1796402106a211140efc6ccebe63c7f588726..5dd6895c4dcbbaefd68edeea7921f48aba70f636 100644 (file)
@@ -447,7 +447,7 @@ void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        switch (cmd.action) {
 
        case LFUN_EXTERNAL_EDIT: {
-               Buffer const & buffer = *cur.bv().buffer();
+               Buffer const & buffer = cur.buffer();
                InsetExternalParams p;
                InsetExternalMailer::string2params(cmd.argument, buffer, p);
                external::editExternal(p, buffer);
@@ -455,10 +455,11 @@ void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_INSET_MODIFY: {
-               Buffer const & buffer = *cur.bv().buffer();
+               Buffer const & buffer = cur.buffer();
                InsetExternalParams p;
                InsetExternalMailer::string2params(cmd.argument, buffer, p);
                setParams(p, buffer);
+#warning is this needed?
                cur.bv().update();
                break;
        }
index 9f2aa8d9fd0b198798f6bb30ef65f17c61389350..41da3b33a9aaf25a36e5c03b10cb248381ac3239 100644 (file)
@@ -163,8 +163,8 @@ void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                params_.placement = params.placement;
                params_.wide      = params.wide;
                params_.sideways  = params.sideways;
-               wide(params_.wide, cur.bv().buffer()->params());
-               sideways(params_.sideways, cur.bv().buffer()->params());
+               wide(params_.wide, cur.buffer().params());
+               sideways(params_.sideways, cur.buffer().params());
                cur.bv().update();
                break;
        }
index 730ddc4202becb06d4fa82c6b03cb1a8d5433177..020f7de95811cd4a48dbb6fd45017e88670ab717 100644 (file)
@@ -191,7 +191,7 @@ void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
-               Buffer const & buffer = *cur.bv().buffer();
+               Buffer const & buffer = cur.buffer();
                InsetGraphicsParams p;
                InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
                if (!p.filename.empty()) {
index 62a9ee02124c36695ebcba198a28fd259e5e7c23..675f80e7955e48341682a65fb2f61989dfe0a434 100644 (file)
@@ -125,7 +125,7 @@ void InsetInclude::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                InsetCommandParams p;
                InsetIncludeMailer::string2params(cmd.argument, p);
                if (!p.getCmdName().empty()) {
-                       set(p, *cur.bv().buffer());
+                       set(p, cur.buffer());
                        cur.bv().update();
                }
                break;
index 063d329c0eecb07b475f434dbfc7594e881ca9e0..983be071640391610c6989fcc83c1927b98b2a5a 100644 (file)
@@ -631,7 +631,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                        maxCols = max(cols, maxCols);
 
                        paste_tabular.reset(
-                               new LyXTabular(cur.bv().buffer()->params(), rows, maxCols));
+                               new LyXTabular(cur.buffer().params(), rows, maxCols));
 
                        string::size_type op = 0;
                        int cell = 0;
@@ -1500,7 +1500,7 @@ bool InsetTabular::copySelection(LCursor & cur)
 
        ostringstream os;
        OutputParams const runparams;
-       paste_tabular->plaintext(*cur.bv().buffer(), os, runparams, 0, true, '\t');
+       paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t');
        cur.bv().stuffClipboard(os.str());
        return true;
 }
@@ -1544,7 +1544,7 @@ void InsetTabular::cutSelection(LCursor & cur)
        if (!cur.selection())
                return;
 
-       bool const track = cur.bv().buffer()->params().tracking_changes;
+       bool const track = cur.buffer().params().tracking_changes;
        int rs, re, cs, ce;
        getSelection(cur, rs, re, cs, ce);
        for (int i = rs; i <= re; ++i)
index 139e4e8884c778fb983af275c80f713a65b034e8..735c96e2fb5adea5b6ef38c2242e410dfe91c117 100644 (file)
@@ -249,7 +249,7 @@ void InsetText::updateLocal(LCursor & cur)
                        }
 
                        cur.clearSelection();
-                       mergeParagraph(cur.bv().buffer()->params(), paragraphs(), 0);
+                       mergeParagraph(cur.buffer().params(), paragraphs(), 0);
                }
        }
 
index 907fc179a8c7d6674d8327c5c6edc293bd7e13d5..87e1153bc39e84b988e199475130a522ac739467 100644 (file)
@@ -81,10 +81,10 @@ public:
                  OutputParams const &) const;
        ///
        int linuxdoc(Buffer const &, std::ostream &,
-                    OutputParams const &) const ;
+                    OutputParams const &) const;
        ///
        int docbook(Buffer const &, std::ostream &,
-                   OutputParams const &) const ;
+                   OutputParams const &) const;
        ///
        void validate(LaTeXFeatures & features) const;
        ///
index 88495f63cf46e733ea2151adb75bc0ba8ac74a58..9f538ab799d20355821b370a6a4e178e2b5797d7 100644 (file)
@@ -30,6 +30,7 @@ namespace {
 
 }
 
+
 WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
        : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
          pendingspace_(false), line_(0)
index 1a4ee55e7396be5055bc9b50f5813fdd4634cedc..6e60ff6c647990e0ca49e1ce9e1bfdd09df55050 100644 (file)
@@ -34,7 +34,7 @@ public:
        ///
        WriteStream(std::ostream & os, bool fragile, bool latex);
        ///
-       explicit WriteStream(std::ostream & os_);
+       explicit WriteStream(std::ostream & os);
        ///
        ~WriteStream();
        ///
index 11ed0a796881e66bbbdcefe1a4212a66425da57e..083860cfa35e290f81d28b4cd3d3e523127a97ab 100644 (file)
@@ -20,6 +20,7 @@
 #include "debug.h"
 #include "metricsinfo.h"
 #include "output_latex.h"
+#include "outputparams.h"
 #include "paragraph.h"
 #include "texrow.h"
 
@@ -59,11 +60,21 @@ void MathMBoxInset::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-void MathMBoxInset::write(WriteStream & os) const
+void MathMBoxInset::write(WriteStream & ws) const
 {
-       os << "\\mbox{\n";
-       text_.write(*bv_->buffer(), os.os());
-       os << "}";
+       if (ws.latex()) {
+               ws << "\\mbox{\n";
+               TexRow texrow;
+               OutputParams runparams;
+               latexParagraphs(*bv_->buffer(), text_.paragraphs(),
+                       ws.os(), texrow, runparams);
+               ws.addlines(texrow.rows());
+               ws << "}";
+       } else {
+               ws << "\\mbox{\n";
+               text_.write(*bv_->buffer(), ws.os());
+               ws << "}";
+       }
 }
 
 
index 4fc2f94a3d76e3b19adda4b70c2081b63dac713c..9c6552c43feee5df4fd0e7952948cac64c475dee 100644 (file)
@@ -313,16 +313,17 @@ int MathNestInset::latex(Buffer const &, std::ostream & os,
 
 void MathNestInset::notifyCursorLeaves(LCursor & cur)
 {
-/*
+#warning look here
+#if 0
        MathArray & ar = cur.cell();
        // remove base-only "scripts"
        for (pos_type i = 0; i + 1 < size(); ++i) {
                MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
-               if (p && p->cell(0).empty() && p->cell(1).empty()) {
+               if (p && p->nargs() == 1) {
                        MathArray ar = p->nuc();
                        erase(i);
                        insert(i, ar);
-                       mathcursor->adjust(i, ar.size() - 1);
+                       cur.adjust(i, ar.size() - 1);
                }
        }
 
@@ -333,10 +334,10 @@ void MathNestInset::notifyCursorLeaves(LCursor & cur)
                if (p && q && p->name() == q->name()) {
                        p->cell(0).append(q->cell(0));
                        erase(i + 1);
-                       mathcursor->adjust(i, -1);
+                       cur.adjust(i, -1);
                }
        }
-*/
+#endif
 }
 
 
index 5863c127f0edda716ce0ae56a08c093127290363..7b645ce9a0696e9467e19b927c2861db6a875946 100644 (file)
@@ -214,8 +214,6 @@ TeXOnePar(Buffer const & buf,
        lyxerr[Debug::LATEX] << "TeXOnePar...     " << &*pit << " '"
                << everypar << "'" << endl;
        BufferParams const & bparams = buf.params();
-
-       InsetOld const * in = pit->inInset();
        bool further_blank_line = false;
        LyXLayout_ptr style;
 
@@ -223,7 +221,7 @@ TeXOnePar(Buffer const & buf,
        // length (all in one row) if that is true then we don't allow
        // any special options in the paragraph and also we don't allow
        // any environment other then "Standard" to be valid!
-       if (in == 0 || !in->forceDefaultParagraphs(in)) {
+       if (!pit->forceDefaultParagraphs()) {
                style = pit->layout();
 
                if (pit->params().startOfAppendix()) {
@@ -383,7 +381,7 @@ paragraphs);
                }
        }
 
-       if (in == 0 || !in->forceDefaultParagraphs(in)) {
+       if (!pit->forceDefaultParagraphs()) {
                further_blank_line = false;
 
                if (further_blank_line) {
@@ -447,12 +445,11 @@ void latexParagraphs(Buffer const & buf,
 
        // if only_body
        while (par != endpar) {
-               InsetOld * in = par->inInset();
                // well we have to check if we are in an inset with unlimited
                // length (all in one row) if that is true then we don't allow
                // any special options in the paragraph and also we don't allow
                // any environment other then "Standard" to be valid!
-               if (in == 0 || !in->forceDefaultParagraphs(in)) {
+               if (!par->forceDefaultParagraphs()) {
                        LyXLayout_ptr const & layout = par->layout();
 
                        if (layout->intitle) {
index d3fa4b2f0acf5c170de140ec1d44018066c9d827..8071f2454e0a665d5422b3d000470665d8891e94 100644 (file)
 
 #include "support/types.h"
 
+
 struct OutputParams {
-        enum FLAVOR {
-                LATEX,
-                PDFLATEX
-        };
+       //
+       enum FLAVOR {
+               LATEX,
+               PDFLATEX
+       };
 
-        OutputParams() : flavor(LATEX), nice(false),
-                          moving_arg(false), free_spacing(false),
-                          use_babel(false), mixed_content(false),
-                          linelen(0) {}
+       OutputParams()
+               : flavor(LATEX), nice(false), moving_arg(false),
+                 free_spacing(false), use_babel(false),
+                 mixed_content(false), linelen(0)
+       {}
 
        /** The latex that we export depends occasionally on what is to
            compile the file.
        */
-        FLAVOR flavor;
+       FLAVOR flavor;
 
        /** Are we to write a 'nice' LaTeX file or not.
            This esentially seems to mean whether InsetInclude, InsetGraphics
@@ -49,17 +52,17 @@ struct OutputParams {
        bool free_spacing;
 
        /** This var is set by the return value from BufferParams::writeLaTeX
-        */
+       */
        bool use_babel;
 
        /** Used for docbook to see if inside a region of mixed content.
            In that case all the white spaces are significant and can not appear
            at the begin or end.
-        */
+       */
        bool mixed_content;
 
-       /** Line lenght to use with ascii export.
-        */
+       /** Line length to use with ascii export.
+       */
        lyx::size_type linelen;
 };
 
index 804e3221bd40a7ab951eba3e34390246b7002ad4..a1c64793ef329e0c7a6f4b01799eb7fec20450dd 100644 (file)
@@ -306,10 +306,7 @@ void Paragraph::insertInset(pos_type pos, InsetBase * inset,
 
 bool Paragraph::insetAllowed(InsetOld_code code)
 {
-       //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
-       if (pimpl_->inset_owner)
-               return pimpl_->inset_owner->insetAllowed(code);
-       return true;
+       return pimpl_->inset_owner->insetAllowed(code);
 }
 
 
@@ -716,19 +713,26 @@ InsetBibitem * Paragraph::bibitem() const
 }
 
 
+bool Paragraph::forceDefaultParagraphs() const
+{
+       return inInset()->forceDefaultParagraphs(inInset());
+}
+
+
+bool Paragraph::autoBreakRows() const
+{
+       return static_cast<InsetText *>(inInset())->getAutoBreakRows();
+}
+
+
 namespace {
 
 // paragraphs inside floats need different alignment tags to avoid
 // unwanted space
 
-bool noTrivlistCentering(UpdatableInset const * inset)
+bool noTrivlistCentering(InsetBase::Code code)
 {
-       if (inset) {
-               InsetBase::Code const code = inset->lyxCode();
-               return code == InsetBase::FLOAT_CODE ||
-                       code == InsetBase::WRAP_CODE;
-       }
-       return false;
+       return code == InsetBase::FLOAT_CODE || code == InsetBase::WRAP_CODE;
 }
 
 
@@ -745,10 +749,10 @@ string correction(string const & orig)
 
 
 string const corrected_env(string const & suffix, string const & env,
-                          UpdatableInset const * inset)
+       InsetBase::Code code)
 {
        string output = suffix + "{";
-       if (noTrivlistCentering(inset))
+       if (noTrivlistCentering(code))
                output += correction(env);
        else
                output += env;
@@ -793,27 +797,25 @@ int Paragraph::startTeXParParams(BufferParams const & bparams,
                break;
        case LYX_ALIGN_LEFT: {
                string output;
-               UpdatableInset const * const inset = pimpl_->inset_owner;
                if (getParLanguage(bparams)->babel() != "hebrew")
-                       output = corrected_env("\\begin", "flushleft", inset);
+                       output = corrected_env("\\begin", "flushleft", ownerCode());
                else
-                       output = corrected_env("\\begin", "flushright", inset);
+                       output = corrected_env("\\begin", "flushright", ownerCode());
                os << output;
                column += output.size();
                break;
        } case LYX_ALIGN_RIGHT: {
                string output;
-               UpdatableInset const * const inset = pimpl_->inset_owner;
                if (getParLanguage(bparams)->babel() != "hebrew")
-                       output = corrected_env("\\begin", "flushright", inset);
+                       output = corrected_env("\\begin", "flushright", ownerCode());
                else
-                       output = corrected_env("\\begin", "flushleft", inset);
+                       output = corrected_env("\\begin", "flushleft", ownerCode());
                os << output;
                column += output.size();
                break;
        } case LYX_ALIGN_CENTER: {
                string output;
-               output = corrected_env("\\begin", "center", pimpl_->inset_owner);
+               output = corrected_env("\\begin", "center", ownerCode());
                os << output;
                column += output.size();
                break;
@@ -854,27 +856,25 @@ int Paragraph::endTeXParParams(BufferParams const & bparams,
                break;
        case LYX_ALIGN_LEFT: {
                string output;
-               UpdatableInset const * const inset = pimpl_->inset_owner;
                if (getParLanguage(bparams)->babel() != "hebrew")
-                       output = corrected_env("\\par\\end", "flushleft", inset);
+                       output = corrected_env("\\par\\end", "flushleft", ownerCode());
                else
-                       output = corrected_env("\\par\\end", "flushright", inset);
+                       output = corrected_env("\\par\\end", "flushright", ownerCode());
                os << output;
                column += output.size();
                break;
        } case LYX_ALIGN_RIGHT: {
                string output;
-               UpdatableInset const * const inset = pimpl_->inset_owner;
                if (getParLanguage(bparams)->babel() != "hebrew")
-                       output = corrected_env("\\par\\end", "flushright", inset);
+                       output = corrected_env("\\par\\end", "flushright", ownerCode());
                else
-                       output = corrected_env("\\par\\end", "flushleft", inset);
+                       output = corrected_env("\\par\\end", "flushleft", ownerCode());
                os << output;
                column += output.size();
                break;
        } case LYX_ALIGN_CENTER: {
                string output;
-               output = corrected_env("\\par\\end", "center", pimpl_->inset_owner);
+               output = corrected_env("\\par\\end", "center", ownerCode());
                os << output;
                column += output.size();
                break;
@@ -902,8 +902,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf,
        // length (all in one row) if that is true then we don't allow
        // any special options in the paragraph and also we don't allow
        // any environment other then "Standard" to be valid!
-       bool asdefault =
-               (inInset() && inInset()->forceDefaultParagraphs(inInset()));
+       bool asdefault = forceDefaultParagraphs();
 
        if (asdefault) {
                style = bparams.getLyXTextClass().defaultLayout();
@@ -1537,7 +1536,7 @@ bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
 {
        return lyxrc.rtl_support
                && getParLanguage(bparams)->RightToLeft()
-               && !(inInset() && inInset()->lyxCode() == InsetBase::ERT_CODE);
+               && ownerCode() != InsetBase::ERT_CODE;
 }
 
 
@@ -1746,11 +1745,6 @@ int Paragraph::id() const
 
 LyXLayout_ptr const & Paragraph::layout() const
 {
-/*
-       InsetBase * inset = inInset();
-       if (inset && inset->lyxCode() == InsetBase::ENVIRONMENT_CODE)
-               return static_cast<InsetEnvironment*>(inset)->layout();
-*/
        return layout_;
 }
 
@@ -1767,6 +1761,13 @@ UpdatableInset * Paragraph::inInset() const
 }
 
 
+InsetBase::Code Paragraph::ownerCode() const
+{
+       return pimpl_->inset_owner
+               ? pimpl_->inset_owner->lyxCode() : InsetBase::NO_CODE;
+}
+
+
 void Paragraph::clearContents()
 {
        text_.clear();
@@ -1798,9 +1799,7 @@ bool Paragraph::isFreeSpacing() const
 
        // for now we just need this, later should we need this in some
        // other way we can always add a function to InsetBase too.
-       if (pimpl_->inset_owner)
-               return pimpl_->inset_owner->lyxCode() == InsetBase::ERT_CODE;
-       return false;
+       return ownerCode() == InsetBase::ERT_CODE;
 }
 
 
@@ -1808,9 +1807,7 @@ bool Paragraph::allowEmpty() const
 {
        if (layout()->keepempty)
                return true;
-       if (pimpl_->inset_owner)
-               return pimpl_->inset_owner->lyxCode() == InsetBase::ERT_CODE;
-       return false;
+       return ownerCode() == InsetBase::ERT_CODE;
 }
 
 
index 6c54e00482f18e130f75e19253e24e39d24115ad..2d25f20d2dd4fa6869af21490bc4813db1aaa177 100644 (file)
@@ -21,6 +21,8 @@
 #include "lyxlayout_ptr_fwd.h"
 #include "RowList_fwd.h"
 
+#include "insets/insetbase.h" // only for InsetBase::Code
+
 #include "support/types.h"
 
 #include <string>
@@ -139,10 +141,16 @@ public:
        ///
        void makeSameLayout(Paragraph const & par);
 
+       ///
+       void setInsetOwner(UpdatableInset * inset);
        ///
        UpdatableInset * inInset() const;
        ///
-       void setInsetOwner(UpdatableInset * inset);
+       InsetBase::Code ownerCode() const;
+       ///
+       bool autoBreakRows() const;
+       ///
+       bool forceDefaultParagraphs() const;
 
        ///
        lyx::pos_type size() const { return text_.size(); }
index 4557c2feb33da5ecb7e414665ce5187a9248b129..9821af99e953ddc5b32cf42f0fcb23759112474a 100644 (file)
@@ -408,18 +408,18 @@ BufferView * LyXText::bv()
 }
 
 
-double LyXText::spacing(Paragraph const & par) const
+BufferView * LyXText::bv() const
 {
-       if (par.params().spacing().isDefault())
-               return bv()->buffer()->params().spacing().getValue();
-       return par.params().spacing().getValue();
+       BOOST_ASSERT(bv_owner != 0);
+       return bv_owner;
 }
 
 
-BufferView * LyXText::bv() const
+double LyXText::spacing(Paragraph const & par) const
 {
-       BOOST_ASSERT(bv_owner != 0);
-       return bv_owner;
+       if (par.params().spacing().isDefault())
+               return bv()->buffer()->params().spacing().getValue();
+       return par.params().spacing().getValue();
 }
 
 
@@ -648,9 +648,8 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const
            && align == LYX_ALIGN_BLOCK
            && !pars_[pit].params().noindent()
            // in tabulars and ert paragraphs are never indented!
-           && (!pars_[pit].inInset()
-               || (pars_[pit].inInset()->lyxCode() != InsetOld::TABULAR_CODE
-                   && pars_[pit].inInset()->lyxCode() != InsetOld::ERT_CODE))
+           && (pars_[pit].ownerCode() != InsetOld::TABULAR_CODE
+                   && pars_[pit].ownerCode() != InsetOld::ERT_CODE)
            && (pars_[pit].layout() != tclass.defaultLayout()
                || bv()->buffer()->params().paragraph_separation ==
                   BufferParams::PARSEP_INDENT))
@@ -1062,8 +1061,7 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
            && cpar.isChangeEdited(0, cur.pos()))
                return;
 
-       LyXTextClass const & tclass =
-               bv()->buffer()->params().getLyXTextClass();
+       LyXTextClass const & tclass = cur.buffer().params().getLyXTextClass();
        LyXLayout_ptr const & layout = cpar.layout();
 
        // this is only allowed, if the current paragraph is not empty
@@ -1091,7 +1089,7 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
        // paragraph before or behind and we should react on that one
        // but we can fix this in 1.3.0 (Jug 20020509)
        bool const isempty = cpar.allowEmpty() && cpar.empty();
-       ::breakParagraph(bv()->buffer()->params(), paragraphs(), cpit,
+       ::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
                         cur.pos(), keep_layout);
 
        cpit = cur.par();
@@ -1652,7 +1650,7 @@ void LyXText::backspace(LCursor & cur)
                // layout. I think it is a real bug of all other
                // word processors to allow it. It confuses the user.
                // Correction: Pasting is always allowed with standard-layout
-               Buffer & buf = *bv()->buffer();
+               Buffer & buf = cur.buffer();
                BufferParams const & bufparams = buf.params();
                LyXTextClass const & tclass = bufparams.getLyXTextClass();
                par_type const cpit = cur.par();
@@ -2096,17 +2094,17 @@ int LyXText::cursorY(CursorSlice const & cur) const
 string LyXText::currentState(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
-       Buffer * buffer = bv()->buffer();
+       Buffer & buf = cur.buffer();
        Paragraph const & par = cur.paragraph();
        std::ostringstream os;
 
-       bool const show_change = buffer->params().tracking_changes
+       bool const show_change = buf.params().tracking_changes
                && cur.pos() != cur.lastpos()
                && par.lookupChange(cur.pos()) != Change::UNCHANGED;
 
        if (show_change) {
                Change change = par.lookupChangeFull(cur.pos());
-               Author const & a = buffer->params().authors().get(change.author);
+               Author const & a = buf.params().authors().get(change.author);
                os << _("Change: ") << a.name();
                if (!a.email().empty())
                        os << " (" << a.email() << ")";
@@ -2118,13 +2116,13 @@ string LyXText::currentState(LCursor & cur)
        // I think we should only show changes from the default
        // font. (Asger)
        LyXFont font = real_current_font;
-       font.reduce(buffer->params().getLyXTextClass().defaultfont());
+       font.reduce(buf.params().getLyXTextClass().defaultfont());
 
        // avoid _(...) re-entrance problem
-       string const s = font.stateText(&buffer->params());
+       string const s = font.stateText(&buf.params());
        os << bformat(_("Font: %1$s"), s);
 
-       // os << bformat(_("Font: %1$s"), font.stateText(&buffer->params));
+       // os << bformat(_("Font: %1$s"), font.stateText(&buf.params));
 
        // The paragraph depth
        int depth = cur.paragraph().getDepth();
@@ -2155,11 +2153,12 @@ string LyXText::currentState(LCursor & cur)
                }
        }
 #ifdef DEVEL_VERSION
-       os << _(", Paragraph: ") << par.id();
+       os << _(", Inset: ") << &cur.inset();
+       os << _(", Paragraph: ") << cur.par();
+       os << _(", Id: ") << par.id();
        os << _(", Position: ") << cur.pos();
        Row & row = cur.textRow();
        os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
-       os << _(", Inset: ") << par.inInset();
 #endif
        return os.str();
 }
@@ -2187,7 +2186,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const
        if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0)
                text.erase();
 
-       string par_text = pars_[pit].asString(*cur.bv().buffer(), false);
+       string par_text = pars_[pit].asString(cur.buffer(), false);
        for (int i = 0; i < lyxrc.label_init_length; ++i) {
                if (par_text.empty())
                        break;
index 4f3244cec6fd854221b2c672f899eec561feba91..426cb90be03222c7d00131b5bbe8c411d4429b8f 100644 (file)
@@ -280,18 +280,19 @@ void LyXText::setLayout(LCursor & cur, string const & layout)
 {
        BOOST_ASSERT(this == cur.text());
        // special handling of new environment insets
-       BufferParams const & params = bv()->buffer()->params();
+       BufferView & bv = cur.bv();
+       BufferParams const & params = bv.buffer()->params();
        LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
        if (lyxlayout->is_environment) {
                // move everything in a new environment inset
                lyxerr << "setting layout " << layout << endl;
-               bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
-               bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
-               bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
+               bv.owner()->dispatch(FuncRequest(LFUN_HOME));
+               bv.owner()->dispatch(FuncRequest(LFUN_ENDSEL));
+               bv.owner()->dispatch(FuncRequest(LFUN_CUT));
                InsetBase * inset = new InsetEnvironment(params, layout);
                insertInset(cur, inset);
                //inset->edit(cur, true);
-               //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
+               //bv.owner()->dispatch(FuncRequest(LFUN_PASTE));
                return;
        }
 
@@ -396,7 +397,7 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
 
                // Update current font
                real_current_font.update(font,
-                                        bv()->buffer()->params().language,
+                                        cur.buffer().params().language,
                                         toggleall);
 
                // Reduce to implicit settings
@@ -419,7 +420,7 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
 
        lyxerr << "pos: " << pos << " posend: " << posend << endl;
 
-       BufferParams const & params = bv()->buffer()->params();
+       BufferParams const & params = cur.buffer().params();
 
        // Don't use forwardChar here as posend might have
        // pos() == lastpos() and forwardChar would miss it.
@@ -775,10 +776,8 @@ void LyXText::setCounter(Buffer const & buf, par_type pit)
                        par_type tmppit = pit;
                        InsetBase * in = 0;
                        bool isOK = false;
-                       while (tmppit != end && pars_[tmppit].inInset()
-                              // the single '=' is intended below
-                              && (in = pars_[tmppit].inInset()))
-                       {
+                       while (tmppit != end) {
+                               in = pars_[tmppit].inInset();
                                if (in->lyxCode() == InsetBase::FLOAT_CODE ||
                                    in->lyxCode() == InsetBase::WRAP_CODE) {
                                        isOK = true;
@@ -872,7 +871,7 @@ void LyXText::insertStringAsLines(LCursor & cur, string const & str)
 
        // only to be sure, should not be neccessary
        cur.clearSelection();
-       bv()->buffer()->insertStringAsLines(pars_, pit, pos, current_font, str);
+       cur.buffer().insertStringAsLines(pars_, pit, pos, current_font, str);
 
        redoParagraphs(cur.par(), endpit);
        cur.resetAnchor();
@@ -1001,12 +1000,12 @@ void LyXText::setCurrentFont(LCursor & cur)
                        }
        }
 
-       BufferParams const & bufparams = bv()->buffer()->params();
+       BufferParams const & bufparams = cur.buffer().params();
        current_font = pars_[pit].getFontSettings(bufparams, pos);
        real_current_font = getFont(pit, pos);
 
        if (cur.pos() == cur.lastpos()
-           && bidi.isBoundary(*bv()->buffer(), pars_[pit], cur.pos())
+           && bidi.isBoundary(cur.buffer(), pars_[pit], cur.pos())
            && !cur.boundary()) {
                Language const * lang = pars_[pit].getParLanguage(bufparams);
                current_font.setLanguage(lang);
@@ -1186,7 +1185,7 @@ void LyXText::cursorLeft(LCursor & cur)
                setCursor(cur, cur.par(), cur.pos() - 1, true, false);
                if (!checkAndActivateInset(cur, false)) {
                        if (false && !boundary &&
-                                       bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
+                                       bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1))
                                setCursor(cur, cur.par(), cur.pos() + 1, true, true);
                }
                return;
@@ -1209,7 +1208,7 @@ void LyXText::cursorRight(LCursor & cur)
        if (cur.pos() != cur.lastpos()) {
                if (!checkAndActivateInset(cur, true)) {
                        setCursor(cur, cur.par(), cur.pos() + 1, true, false);
-                       if (false && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
+                       if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(),
                                                         cur.pos()))
                                setCursor(cur, cur.par(), cur.pos(), true, true);
                }
index 7fb5790022b224119a1f76d3c31e4d20b9fbe151..a2f7b01560edd8fdda0efa344bdb3c78a0f17011 100644 (file)
@@ -102,9 +102,9 @@ namespace {
                if (font.language() != ignore_language ||
                                font.number() != LyXFont::IGNORE) {
                        Paragraph & par = cur.paragraph();
-                       text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
+                       text->bidi.computeTables(par, cur.buffer(), cur.textRow());
                        if (cur.boundary() !=
-                                       text->bidi.isBoundary(*cur.bv().buffer(), par,
+                                       text->bidi.isBoundary(cur.buffer(), par,
                                                        cur.pos(),
                                                        text->real_current_font))
                                text->setCursor(cur, cur.par(), cur.pos(),
@@ -294,7 +294,7 @@ void LyXText::cursorPrevious(LCursor & cur)
        lyx::par_type cpar = cur.par();
 
        int x = cur.x_target();
-       int y = bv()->top_y();
+       int y = cur.bv().top_y();
        setCursorFromCoordinates(cur, x, y);
 
        if (cpar == cur.par() && cpos == cur.pos()) {
@@ -303,7 +303,7 @@ void LyXText::cursorPrevious(LCursor & cur)
                cursorUp(cur);
        }
 
-       bv()->updateScrollbar();
+       cur.bv().updateScrollbar();
        finishUndo();
 }
 
@@ -314,7 +314,7 @@ void LyXText::cursorNext(LCursor & cur)
        lyx::par_type cpar = cur.par();
 
        int x = cur.x_target();
-       int y = bv()->top_y() + bv()->workHeight();
+       int y = cur.bv().top_y() + cur.bv().workHeight();
        setCursorFromCoordinates(cur, x, y);
 
        if (cpar == cur.par() && cpos == cur.pos()) {
@@ -323,7 +323,7 @@ void LyXText::cursorNext(LCursor & cur)
                cursorDown(cur);
        }
 
-       bv()->updateScrollbar();
+       cur.bv().updateScrollbar();
        finishUndo();
 }