From 52ed731842518e715da642fee562cf4bb056f0da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 27 Mar 2004 12:46:30 +0000 Subject: [PATCH] rest of patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8544 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 123 +++----------------------------- src/buffer.h | 58 --------------- src/cursor.C | 6 ++ src/cursor.h | 2 + src/graphics/PreviewLoader.C | 6 +- src/graphics/Previews.C | 6 +- src/mathed/math_macrotable.C | 5 ++ src/mathed/math_macrotemplate.C | 8 +-- src/mathed/math_nestinset.C | 9 +-- src/undo.C | 7 +- 10 files changed, 41 insertions(+), 189 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 904d63cc4a..cde602284f 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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" @@ -65,11 +66,10 @@ #include "support/path.h" #include "support/textutils.h" #include "support/tostr.h" +#include "support/std_sstream.h" #include -#include "support/std_sstream.h" - #include #include @@ -458,7 +458,7 @@ void Buffer::insertStringAsLines(ParagraphList & pars, bool space_inserted = true; bool autobreakrows = !pars[par].inInset() || static_cast(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 & 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 > & 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(*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(paragraphs()); - return inset_iterator(pars, 0); -} - - -Buffer::inset_iterator Buffer::inset_const_iterator_end() const -{ - ParagraphList & pars = const_cast(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); -} diff --git a/src/buffer.h b/src/buffer.h index 17f689a3a3..50b1cc2427 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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 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 diff --git a/src/cursor.C b/src/cursor.C index 1d29a5dbb2..52d971d211 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -1335,6 +1335,12 @@ void LCursor::undispatched() } +void LCursor::dispatched() +{ + disp_.dispatched(true); +} + + void LCursor::noUpdate() { disp_.update(false); diff --git a/src/cursor.h b/src/cursor.h index ec1002aebc..d39c2e3e52 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -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(); diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 71ada4dba2..130178f849 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -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); diff --git a/src/graphics/Previews.C b/src/graphics/Previews.C index c5ca02ca7c..0d012a38e4 100644 --- a/src/graphics/Previews.C +++ b/src/graphics/Previews.C @@ -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(); diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index a0456960f9..16ef1dbb9a 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -14,6 +14,8 @@ #include "math_macrotemplate.h" #include "debug.h" +#include + 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; } diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 7efaee6fb5..90e0e49ac0 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -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; } diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 93258bf57b..632ee7c150 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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; } diff --git a/src/undo.C b/src/undo.C index fb6bf776fe..3530a88787 100644 --- a/src/undo.C +++ b/src/undo.C @@ -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); -- 2.39.2