On Monday 08 July 2002 11:34 am, Andre Poenitz wrote: > On Mon, Jul 08, 2002 at 12:29:46PM +0200, Juergen Vigna wrote: > > >I do not want any preview code in the BufferView (nor in the Buffer, nor > > > in LyXText etc for that matter) And if that's not reason enough I'll > > > call my big brothers... > > > > Start to call then :) > > Laaaaaaaaaaaaarss! > > > This is not "preview" stuff it is just "loading graphics on demand" > > stuff and I think this can be in BufferView! > > But if it can be done outside, why should BufferView know of its existence > at all? > > > Not all of lyx graphics is connected to "preview", is it? > > [No. And it hopefully wont...] > > Andre'
You two, stop squabbling NOW! ;-) The preview code is entirely separate from the rest of LyX so we can do what we like. Attached are Previews.h and PreviewLoader.h, the interface as seen by the rest of LyX. At the moment, BufferView::buffer calls Previews::generateBufferPreviews(buffer) to start the conversion of all snippets. I'm sure we can pass it a paragraph_iterator position as well so that we only generate previews for 20 equations on either side or something. Similarly, an individual inset calls PreviewLoader::add(latex_snippet). Followed by PreviewLoader::startLoading(). It should be possible to make startLoading a little more intelligent, so that we load the 20 or so equations on either side of the snippets currently in the queue as well. Ok, Ok. We don't have a paragraph_iterator. Could you two great minds think of ways of improving the interface to do what we'd like to do. The rest should be hidden inside the implementation. A
// -*- C++ -*- /** * \file Previews.h * Copyright 2002 the LyX Team * Read the file COPYING * * \author Angus Leeming <[EMAIL PROTECTED]> * * grfx::Previews is a singleton class that stores the grfx::PreviewLoader * for each buffer requiring one. */ #ifndef PREVIEWS_H #define PREVIEWS_H #ifdef __GNUG__ #pragma interface #endif #include "LString.h" #include <boost/utility.hpp> #include <boost/scoped_ptr.hpp> class Buffer; namespace grfx { class PreviewLoader; class Previews : boost::noncopyable { public: /// a wrapper for lyxrc.preview static bool activated(); /// This is a singleton class. Get the instance. static Previews & get(); /** Returns the PreviewLoader for this buffer. * Used by individual insets to update their own preview. * We assert that (buffer != 0) but do not pass a Buffer & * so that insets do not need to #include buffer.h */ PreviewLoader & loader(Buffer * buffer); /** Called from the Buffer d-tor. * If (buffer == 0), does nothing. */ void removeLoader(Buffer * buffer); /** For a particular buffer, initiate the generation of previews * for each and every snippetof LaTeX that's of interest with * a single forked process. * If (buffer == 0), does nothing. */ void generateBufferPreviews(Buffer * buffer); private: /** Make the c-tor, d-tor private so we can control how many objects * are instantiated. */ Previews(); /// ~Previews(); /// Use the Pimpl idiom to hide the internals. class Impl; /// The pointer never changes although *pimpl_'s contents may. boost::scoped_ptr<Impl> const pimpl_; }; } // namespace grfx #endif // PREVIEWS_H
// -*- C++ -*- /** * \file PreviewLoader.h * Copyright 2002 the LyX Team * Read the file COPYING * * \author Angus Leeming <[EMAIL PROTECTED]> * * grfx::PreviewLoader collects latex snippets together. Then, on a * startLoading() call, these are dumped to file and processed, converting * each snippet to a separate bitmap image file. Once a bitmap file is ready * to be loaded back into LyX, the PreviewLoader emits a readyToDisplay signal * to inform the initiating process. */ #ifndef PREVIEWLOADER_H #define PREVIEWLOADER_H #ifdef __GNUG__ #pragma interface #endif #include "LString.h" #include <boost/utility.hpp> #include <boost/scoped_ptr.hpp> #include <boost/signals/signal1.hpp> class Buffer; namespace grfx { class PreviewImage; class PreviewLoader : boost::noncopyable { public: /** We need buffer because we require the preamble to the * LaTeX file. */ PreviewLoader(Buffer const & buffer); /// ~PreviewLoader(); /** Is there an image already associated with this snippet of LaTeX? * If so, returns a pointer to it, else returns 0. */ PreviewImage const * preview(string const & latex_snippet) const; /// enum Status { /// NotFound, /// InQueue, /// Processing, /// Ready }; /// How far have we got in loading the image? Status status(string const & latex_snippet) const; /// Add a snippet of LaTeX to the queue for processing. void add(string const & latex_snippet); /// Remove this snippet of LaTeX from the PreviewLoader. void remove(string const & latex_snippet); /** We have accumulated several latex snippets with status "InQueue". * Initiate their transformation into bitmap images. */ void startLoading(); /// Emit this signal when an image is ready for display. boost::signal1<void, PreviewImage const &> imageReady; private: /// Use the Pimpl idiom to hide the internals. class Impl; /// The pointer never changes although *pimpl_'s contents may. boost::scoped_ptr<Impl> const pimpl_; }; } // namespace grfx #endif // PREVIEWLOADER_H