]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Abdel is right.
[lyx.git] / src / Buffer.cpp
index 4519737d6bf8f005b09e81ac2fcf4fca43720bfe..78aaf190701e76ea13583563aa4187964d6189a9 100644 (file)
@@ -117,7 +117,7 @@ namespace os = support::os;
 
 namespace {
 
-int const LYX_FORMAT = 316; // JSpitzm: subfig support
+int const LYX_FORMAT = 317; // Uwe Stöhr: float placement support for wrap floats
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -167,9 +167,6 @@ public:
         */
        bool file_fully_loaded;
 
-       /// our Text that should be wrapped in an InsetText
-       InsetText inset;
-
        ///
        mutable TocBackend toc_backend;
 
@@ -209,6 +206,9 @@ public:
        mutable EmbeddedFileList bibfilesCache_;
 
        mutable RefCache ref_cache_;
+
+       /// our Text that should be wrapped in an InsetText
+       InsetText inset;
 };
 
 /// Creates the per buffer temporary directory
@@ -233,13 +233,11 @@ static FileName createBufferTmpDir()
 Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
        : parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
          read_only(readonly_), filename(file), file_fully_loaded(false),
-         inset(params), toc_backend(&parent), macro_lock(false),
+         toc_backend(&parent), macro_lock(false),
          embedded_files(), timestamp_(0), checksum_(0), wa_(0), 
          undo_(parent)
 {
        temppath = createBufferTmpDir();
-       inset.setBuffer(parent);
-       inset.setAutoBreakRows(true);
        lyxvc.setBuffer(&parent);
        if (use_gui)
                wa_ = new frontend::WorkAreaManager;
@@ -251,6 +249,9 @@ Buffer::Buffer(string const & file, bool readonly)
 {
        LYXERR(Debug::INFO, "Buffer::Buffer()");
 
+       d->inset.setBuffer(*this);
+       d->inset.initParagraphs(*this);
+       d->inset.setAutoBreakRows(true);
        d->inset.getText(0)->setMacrocontextPosition(par_iterator_begin());
 }
 
@@ -264,16 +265,9 @@ Buffer::~Buffer()
        // GuiView already destroyed
        gui_ = 0;
 
-       Buffer const * master = masterBuffer();
-       if (master != this && use_gui) {
-               // We are closing buf which was a child document so we
-               // must update the labels and section numbering of its master
-               // Buffer.
-               updateLabels(*master);
-               master->updateMacros();
-       }
-
-       resetChildDocuments(false);
+       // clear references to children in macro tables
+       d->children_positions.clear();
+       d->position_to_children.clear();
 
        if (!d->temppath.destroyDirectory()) {
                Alert::warning(_("Could not remove temporary directory"),
@@ -598,7 +592,7 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
                if (*cit == '\n') {
                        if (autobreakrows && (!par.empty() || par.allowEmpty())) {
                                breakParagraph(params(), pars, pit, pos,
-                                              par.layout()->isEnvironment());
+                                              par.layout().isEnvironment());
                                ++pit;
                                pos = 0;
                                space_inserted = true;
@@ -1068,6 +1062,8 @@ void Buffer::writeLaTeXSource(odocstream & os,
                           OutputParams const & runparams_in,
                           bool const output_preamble, bool const output_body) const
 {
+       // The child documents, if any, shall be already loaded at this point.
+
        OutputParams runparams = runparams_in;
 
        // validate the buffer.
@@ -1132,12 +1128,10 @@ void Buffer::writeLaTeXSource(odocstream & os,
        
        LYXERR(Debug::INFO, "preamble finished, now the body.");
 
-       // load children, if not already done. 
-       // This includes an updateMacro() call.
        // Don't move this behind the parent_buffer=0 code below,
        // because then the macros will not get the right "redefinition"
        // flag as they don't see the parent macros which are output before.
-       loadChildDocuments();
+       updateMacros();
 
        // fold macros if possible, still with parent buffer as the
        // macros will be put in the prefix anyway.
@@ -1291,7 +1285,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
 
        params().documentClass().counters().reset();
 
-       loadChildDocuments();
+       updateMacros();
 
        sgml::openTag(os, top);
        os << '\n';
@@ -1345,7 +1339,7 @@ void Buffer::validate(LaTeXFeatures & features) const
 {
        params().validate(features);
 
-       loadChildDocuments();
+       updateMacros();
 
        for_each(paragraphs().begin(), paragraphs().end(),
                 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
@@ -1370,7 +1364,7 @@ void Buffer::getLabelList(vector<docstring> & list) const
                return;
        }
 
-       loadChildDocuments();
+       updateMacros();
 
        for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
                it.nextInset()->getLabelList(list);
@@ -1840,7 +1834,7 @@ void Buffer::updateEnvironmentMacros(DocIterator & it,
                // increased depth?
                if ((par.params().depth() > depth
                     || par.params().leftIndent() != leftIndent)
-                   && par.layout()->isEnvironment()) {
+                   && par.layout().isEnvironment()) {
                        updateBlockMacros(it, scope);
                        continue;
                }
@@ -1930,7 +1924,7 @@ void Buffer::updateBlockMacros(DocIterator & it, DocIterator & scope) const
        // set scope for macros in this paragraph:
        // * either the "old" outer scope
        // * or the scope ending after the environment
-       if (par.layout()->isEnvironment()) {
+       if (par.layout().isEnvironment()) {
                // find end of environment block,
                DocIterator envEnd = it;
                pit_type n = it.lastpit() + 1;
@@ -2358,49 +2352,6 @@ void Buffer::autoSave() const
 }
 
 
-void Buffer::resetChildDocuments(bool close_them) const
-{
-       if (text().empty())
-               return;
-
-       for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
-               if (it->lyxCode() != INCLUDE_CODE)
-                       continue;
-               InsetCommand const & inset = static_cast<InsetCommand const &>(*it);
-               InsetCommandParams const & ip = inset.params();
-
-               resetParentBuffer(this, ip, close_them);
-       }
-
-       // clear references to children in macro tables
-       d->children_positions.clear();
-       d->position_to_children.clear();
-}
-
-
-void Buffer::loadChildDocuments() const
-{
-       bool parse_error = false;
-               
-       for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
-               if (it->lyxCode() != INCLUDE_CODE)
-                       continue;
-               InsetCommand const & inset = static_cast<InsetCommand const &>(*it);
-               InsetCommandParams const & ip = inset.params();
-               Buffer * child = loadIfNeeded(*this, ip);
-               if (!child)
-                       continue;
-               parse_error |= !child->errorList("Parse").empty();
-               child->loadChildDocuments();
-       }
-
-       if (use_gui && masterBuffer() == this)
-               updateLabels(*this);
-
-       updateMacros();
-}
-
-
 string Buffer::bufferFormat() const
 {
        if (isDocBook())