]> git.lyx.org Git - features.git/commitdiff
rest of patch
authorAndré Pönitz <poenitz@gmx.net>
Sat, 27 Mar 2004 12:46:30 +0000 (12:46 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 27 Mar 2004 12:46:30 +0000 (12:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8544 a592a061-630c-0410-9148-cb99ea01b6c8

src/buffer.C
src/buffer.h
src/cursor.C
src/cursor.h
src/graphics/PreviewLoader.C
src/graphics/Previews.C
src/mathed/math_macrotable.C
src/mathed/math_macrotemplate.C
src/mathed/math_nestinset.C
src/undo.C

index 904d63cc4afefff7c33d22e1c43cb4d7fbff7c67..cde602284f98c40d18f8587713ac38592b36c508 100644 (file)
@@ -25,6 +25,7 @@
 #include "format.h"
 #include "funcrequest.h"
 #include "gettext.h"
+#include "insetiterator.h"
 #include "iterators.h"
 #include "language.h"
 #include "LaTeX.h"
 #include "support/path.h"
 #include "support/textutils.h"
 #include "support/tostr.h"
+#include "support/std_sstream.h"
 
 #include <boost/bind.hpp>
 
-#include "support/std_sstream.h"
-
 #include <iomanip>
 #include <stack>
 
@@ -458,7 +458,7 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
        bool space_inserted = true;
        bool autobreakrows = !pars[par].inInset() ||
                static_cast<InsetText *>(pars[par].inInset())->getAutoBreakRows();
-       for(string::const_iterator cit = str.begin();
+       for (string::const_iterator cit = str.begin();
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
                        if (autobreakrows && (!pars[par].empty() || pars[par].allowEmpty())) {
@@ -1183,15 +1183,17 @@ void Buffer::getLabelList(std::vector<string> & list) const
        /// if this is a child document and the parent is already loaded
        /// Use the parent's list instead  [ale990407]
        Buffer const * tmp = getMasterBuffer();
+       if (!tmp) {
+               lyxerr << "getMasterBuffer() failed!" << endl;
+               BOOST_ASSERT(tmp);
+       }
        if (tmp != this) {
                tmp->getLabelList(list);
                return;
        }
 
-       for (inset_iterator it = inset_const_iterator_begin();
-            it != inset_const_iterator_end(); ++it) {
-               it->getLabelList(*this, list);
-       }
+       for (InsetIterator it(inset()); it; ++it)
+               it.nextInset()->getLabelList(*this, list);
 }
 
 
@@ -1202,13 +1204,13 @@ void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys)
        /// if this is a child document and the parent is already loaded
        /// use the parent's list instead  [ale990412]
        Buffer const * tmp = getMasterBuffer();
+       BOOST_ASSERT(tmp);
        if (tmp != this) {
                tmp->fillWithBibKeys(keys);
                return;
        }
 
-       for (inset_iterator it = inset_const_iterator_begin();
-               it != inset_const_iterator_end(); ++it) {
+       for (InsetIterator it(inset()); it; ++it) {
                if (it->lyxCode() == InsetOld::BIBTEX_CODE) {
                        InsetBibtex const & inset =
                                dynamic_cast<InsetBibtex const &>(*it);
@@ -1300,17 +1302,6 @@ bool Buffer::isMultiLingual() const
 }
 
 
-void Buffer::inset_iterator::setParagraph()
-{
-       while (pit != par_type(pars_->size())) {
-               it = (*pars_)[pit].insetlist.begin();
-               if (it != (*pars_)[pit].insetlist.end())
-                       return;
-               ++pit;
-       }
-}
-
-
 ParIterator Buffer::getParFromID(int id) const
 {
 #warning FIXME: const correctness! (Andre)
@@ -1485,95 +1476,3 @@ Buffer const * Buffer::getMasterBuffer() const
 
        return this;
 }
-
-
-Buffer::inset_iterator::inset_iterator(ParagraphList & pars, base_type p)
-       : pit(p), pars_(&pars)
-{
-       setParagraph();
-}
-
-
-Buffer::inset_iterator Buffer::inset_iterator_begin()
-{
-       return inset_iterator(paragraphs(), 0);
-}
-
-
-Buffer::inset_iterator Buffer::inset_iterator_end()
-{
-       return inset_iterator(paragraphs(), paragraphs().size());
-}
-
-
-Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
-{
-       ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
-       return inset_iterator(pars, 0);
-}
-
-
-Buffer::inset_iterator Buffer::inset_const_iterator_end() const
-{
-       ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
-       return inset_iterator(pars, pars.size());
-}
-
-
-Buffer::inset_iterator & Buffer::inset_iterator::operator++()
-{
-       if (pit != par_type(pars_->size())) {
-               ++it;
-               if (it == (*pars_)[pit].insetlist.end()) {
-                       ++pit;
-                       setParagraph();
-               }
-       }
-       return *this;
-}
-
-
-Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
-{
-       inset_iterator tmp = *this;
-       ++*this;
-       return tmp;
-}
-
-
-Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
-{
-       return *it->inset;
-}
-
-
-Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
-{
-       return it->inset;
-}
-
-
-lyx::par_type Buffer::inset_iterator::getPar() const
-{
-       return pit;
-}
-
-
-lyx::pos_type Buffer::inset_iterator::getPos() const
-{
-       return it->pos;
-}
-
-
-bool operator==(Buffer::inset_iterator const & iter1,
-               Buffer::inset_iterator const & iter2)
-{
-       return iter1.pit == iter2.pit && iter1.it == iter2.it;
-}
-
-
-bool operator!=(Buffer::inset_iterator const & iter1,
-               Buffer::inset_iterator const & iter2)
-{
-       return !(iter1 == iter2);
-}
index 17f689a3a3d5198f1a45180e89fafdcb33275c63..50b1cc2427baf88813310232f8826c6c77b70dfd 100644 (file)
@@ -286,58 +286,6 @@ public:
        TexRow & texrow();
        TexRow const & texrow() const;
 
-       class inset_iterator {
-       public:
-               typedef std::input_iterator_tag iterator_category;
-               typedef InsetBase value_type;
-               typedef ptrdiff_t difference_type;
-               typedef InsetBase * pointer;
-               typedef InsetBase & reference;
-               typedef lyx::par_type base_type;
-
-               ///
-               inset_iterator(ParagraphList & pars, base_type p);
-
-               /// prefix ++
-               inset_iterator & operator++();
-               /// postfix ++
-               inset_iterator operator++(int);
-               ///
-               reference operator*();
-               ///
-               pointer operator->();
-
-               ///
-               lyx::par_type getPar() const;
-               ///
-               lyx::pos_type getPos() const;
-               ///
-               friend
-               bool operator==(inset_iterator const & iter1,
-                               inset_iterator const & iter2);
-       private:
-               ///
-               void setParagraph();
-               ///
-               lyx::par_type pit;
-               ///
-               InsetList::iterator it;
-       public:
-               ParagraphList * pars_;
-       };
-
-       /// return an iterator to all *top-level* insets in the buffer
-       inset_iterator inset_iterator_begin();
-
-       /// return the end of all *top-level* insets in the buffer
-       inset_iterator inset_iterator_end();
-
-       /// return a const iterator to all *top-level* insets in the buffer
-       inset_iterator inset_const_iterator_begin() const;
-
-       /// return the const end of all *top-level* insets in the buffer
-       inset_iterator inset_const_iterator_end() const;
-
        ///
        ParIterator par_iterator_begin();
        ///
@@ -376,10 +324,4 @@ private:
        boost::scoped_ptr<Impl> const pimpl_;
 };
 
-bool operator==(Buffer::inset_iterator const & iter1,
-               Buffer::inset_iterator const & iter2);
-
-bool operator!=(Buffer::inset_iterator const & iter1,
-               Buffer::inset_iterator const & iter2);
-
 #endif
index 1d29a5dbb217c7c7feb5e307aec7f551138ec618..52d971d211d9b399c73337a6287f634f68ac9d6a 100644 (file)
@@ -1335,6 +1335,12 @@ void LCursor::undispatched()
 }
 
 
+void LCursor::dispatched()
+{
+       disp_.dispatched(true);
+}
+
+
 void LCursor::noUpdate()
 {
        disp_.update(false);
index ec1002aebc6a2e912831e2759df4c83d74029898..d39c2e3e521b227e907907e3e85af24f32932d8a 100644 (file)
@@ -168,6 +168,8 @@ public:
        void update();
        /// the event was not (yet) dispatched
        void undispatched();
+       /// the event was already dispatched
+       void dispatched();
        /// don't call update() when done
        void noUpdate();
 
index 71ada4dba2baaf4e78f82e67928b82c5f1e8dfa5..130178f8497623318c730367aec08c82d832827c 100644 (file)
@@ -17,6 +17,7 @@
 #include "converter.h"
 #include "debug.h"
 #include "format.h"
+#include "insetiterator.h"
 #include "LColor.h"
 #include "lyxrc.h"
 #include "outputparams.h"
@@ -599,10 +600,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
           << "\n";
 
        // Loop over the insets in the buffer and dump all the math-macros.
-       Buffer::inset_iterator it  = buffer_.inset_const_iterator_begin();
-       Buffer::inset_iterator end = buffer_.inset_const_iterator_end();
-
-       for (; it != end; ++it)
+       for (InsetIterator it(buffer_.inset()); it; ++it)
                if (it->lyxCode() == InsetOld::MATHMACRO_CODE)
                        it->latex(buffer_, os, runparams);
 
index c5ca02ca7c3edf5b08aa70548b3af419bfa1707e..0d012a38e455c8da6d05f3195d1463439ea6a716 100644 (file)
@@ -14,6 +14,7 @@
 #include "PreviewLoader.h"
 
 #include "buffer.h"
+#include "insetiterator.h"
 #include "lyxrc.h"
 #include "paragraph.h"
 
@@ -82,10 +83,7 @@ void Previews::generateBufferPreviews(Buffer const & buffer) const
 {
        PreviewLoader & ploader = loader(buffer);
 
-       Buffer::inset_iterator it  = buffer.inset_const_iterator_begin();
-       Buffer::inset_iterator end = buffer.inset_const_iterator_end();
-
-       for (; it != end; ++it)
+       for (InsetIterator it(buffer.inset()); it; ++it)
                it->addPreview(ploader);
 
        ploader.startLoading();
index a0456960f9e1be832e89693adaab9a1d61aede90..16ef1dbb9a0a04f07bb4ef005e935e9a67be3528 100644 (file)
@@ -14,6 +14,8 @@
 #include "math_macrotemplate.h"
 #include "debug.h"
 
+#include <boost/assert.hpp>
+
 
 using std::string;
 using std::endl;
@@ -42,6 +44,7 @@ MathAtom & MathMacroTable::provide(string const & name)
        if (pos == macro_table.end()) {
                lyxerr << "MathMacroTable::provideTemplate: no template with name '"
                       << name << "' available." << endl;
+               BOOST_ASSERT(false);
        }
        return pos->second;
 }
@@ -49,6 +52,8 @@ MathAtom & MathMacroTable::provide(string const & name)
 
 void MathMacroTable::create(MathAtom const & at)
 {
+       lyxerr << "MathMacroTable::create: '"
+               << at->asMacroTemplate()->name() << "'" << endl;
        macro_table[at->asMacroTemplate()->name()] = at;
 }
 
index 7efaee6fb5267b7b914d6921c80a83a5037cb907..90e0e49ac045e339d1b137d85959527a1fd38ef2 100644 (file)
@@ -83,10 +83,10 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi);
        cell(1).metrics(mi);
-       dim_.wid = cell(0).width() + cell(1).width() + 10;
-       dim_.asc = std::max(cell(0).ascent(),  cell(1).ascent())  + 2;
-       dim_.des = std::max(cell(0).descent(), cell(1).descent()) + 2;
-       dim = dim_;
+       dim.wid = cell(0).width() + cell(1).width() + 10;
+       dim.asc = std::max(cell(0).ascent(),  cell(1).ascent())  + 2;
+       dim.des = std::max(cell(0).descent(), cell(1).descent()) + 2;
+       dim_ = dim;
 }
 
 
index 93258bf57ba42748268c5bdea4268f4f1ea1ad99..632ee7c150ef49626c6957b3ac71e36984cf696c 100644 (file)
@@ -335,7 +335,7 @@ void MathNestInset::handleFont2(LCursor & cur, string const & arg)
 
 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
-       lyxerr << "MathNestInset: request: " << cmd << std::endl;
+       //lyxerr << "MathNestInset: request: " << cmd << std::endl;
        //CursorSlice sl = cur.current();
 
        switch (cmd.action) {
@@ -739,11 +739,6 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                cur.insert(MathAtom(new MathSpaceInset(",")));
                break;
 
-       case LFUN_UNDO:
-#warning look here
-               //cur.bv().owner()->message(_("Invalid action in math mode!"));
-               break;
-
        case LFUN_INSET_ERT:
                // interpret this as if a backslash was typed
                recordUndo(cur, Undo::ATOMIC);
@@ -890,12 +885,14 @@ bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
        return ret;
 }
 
+
 void MathNestInset::edit(LCursor & cur, bool left)
 {
        cur.push(*this);
        cur.idx() = left ? 0 : cur.lastidx();
        cur.pos() = left ? 0 : cur.lastpos();
        cur.resetAnchor();
+       lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
 }
 
 
index fb6bf776fe33da7f7b58349ac49e6dff7da19273..3530a8878739319efb89adccc7a5db74ab9813e2 100644 (file)
@@ -31,6 +31,8 @@ using std::advance;
 
 using lyx::par_type;
 
+using std::endl;
+
 
 namespace {
 
@@ -156,8 +158,11 @@ bool textUndoOrRedo(BufferView & bv,
        DocumentIterator dit =
                undo.cursor.asDocumentIterator(&bv.buffer()->inset());
        if (dit.inMathed()) {
-               // not much to be done
+               // Easy way out: store a full cell.
+               otherstack.top().array = asString(dit.cell());
        } else {
+               // As cells might be too large in texted, store just a part
+               // of the paragraph list.
                otherstack.top().pars.clear();
                LyXText * text = dit.text();
                BOOST_ASSERT(text);