OK, this is the second time a working IG viewing is available, this time its done better (or so I hope). It is currently synchronous, that means that lyx waits until all the images are loaded before it continues to do anything. To make it asynchronous I need to be able to fork a second process to do the conversion, it needs to be checked whether the converter is thread-safe enough to do it. Another thing needed is messaging, I dont want to make IG fully multi-threaded so upon image loading completion I need to be able to send a message, I intend to investigate creating some sort of messaging by using x-windows messages to Xforms, but this might be a problem. I'm open to suggestions on this. -- Baruch Even http://baruch.ev-en.org/
Index: src/graphics/GraphicsCache.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsCache.C,v retrieving revision 1.8 diff -u -r1.8 GraphicsCache.C --- src/graphics/GraphicsCache.C 2000/11/21 15:46:12 1.8 +++ src/graphics/GraphicsCache.C 2001/02/18 19:36:04 @@ -36,14 +36,8 @@ GraphicsCache::~GraphicsCache() { - // Free the map. - //std::foreach(map.begin(), map.end(), ...); -//#warning This is a bogus reason to not clean up after your self. (Lgb) - // TODO: Clean up here (BE) - - // This is not really needed, it will only happen on program close and in - // any case the OS will release those resources (not doing it may have - // a good effect on closing time). + // The map elements should have already been eliminated. + Assert(cache.empty()); delete singleton; } @@ -78,6 +72,7 @@ // We do not destroy the GraphicsCacheItem since we are here because // the last copy of it is being erased. - if (cache.find(filename) != cache.end()) - cache.erase(filename); + CacheType::iterator it = cache.find(filename); + if (it != cache.end()) + cache.erase(it); } Index: src/graphics/GraphicsCacheItem.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsCacheItem.C,v retrieving revision 1.8 diff -u -r1.8 GraphicsCacheItem.C --- src/graphics/GraphicsCacheItem.C 2001/02/08 13:06:55 1.8 +++ src/graphics/GraphicsCacheItem.C 2001/02/18 19:36:05 @@ -82,18 +82,16 @@ void GraphicsCacheItem::destroy() { - if (pimpl) { - --(pimpl->refCount); - if (pimpl->refCount == 0) { - { // We are deleting the pimpl but we want to mark it deleted - // even before it is deleted. - GraphicsCacheItem_pimpl * temp = pimpl; - pimpl = 0; - delete temp; temp = 0; - } - GraphicsCache * gc = GraphicsCache::getInstance(); - gc->removeFile(filename_); - } + if (!pimpl) + return; + + --(pimpl->refCount); + if (pimpl->refCount == 0) { + delete pimpl; + pimpl = 0; + + GraphicsCache * gc = GraphicsCache::getInstance(); + gc->removeFile(filename_); } } Index: src/graphics/GraphicsCacheItem_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsCacheItem_pimpl.C,v retrieving revision 1.10 diff -u -r1.10 GraphicsCacheItem_pimpl.C --- src/graphics/GraphicsCacheItem_pimpl.C 2001/02/12 14:09:08 1.10 +++ src/graphics/GraphicsCacheItem_pimpl.C 2001/02/18 19:36:05 @@ -108,8 +108,8 @@ temp = ChangeExtension(filename, string()); // Add some stuff to have it a unique temp file. + // This tempfile is deleted in loadXPMImage after it is loaded to memory. xpmfile = lyx::tempName(string(), temp); -#warning When is this tempfile unlinked? (Lgb) xpmfile = ChangeExtension(xpmfile, ".xpm"); command += xpmfile; @@ -136,7 +136,7 @@ { lyxerr << "Loading XPM Image... "; - if (imageLoader->loadImage(xpmfile)) { + if (imageLoader->loadImage(xpmfile) == ImageLoader::OK) { lyxerr << "Success." << endl; image_ = imageLoader->getImage(); imageStatus_ = GraphicsCacheItem::Loaded; Index: src/insets/insetgraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v retrieving revision 1.31 diff -u -r1.31 insetgraphics.C --- src/insets/insetgraphics.C 2001/02/08 13:06:55 1.31 +++ src/insets/insetgraphics.C 2001/02/18 19:36:07 @@ -48,6 +48,7 @@ * If we are trying to create a file in a read-only directory and there are graphics that need converting, the converting will fail because it is done in-place, into the same directory as the original image. + This needs to be fixed in the src/converter.C file TODO Before initial production release: * Replace insetfig everywhere @@ -170,7 +171,7 @@ // Initialize only those variables that do not have a constructor. InsetGraphics::InsetGraphics() - : cacheHandle(0), pixmap(0), updateImage(false) + : cacheHandle(0), imageLoaded(false) {} InsetGraphics::~InsetGraphics() @@ -217,7 +218,8 @@ int InsetGraphics::ascent(BufferView *, LyXFont const &) const { - if (pixmap) + LyXImage * pixmap = 0; + if (cacheHandle && (pixmap = cacheHandle->getImage())) return pixmap->getHeight(); else return 50; @@ -233,7 +235,9 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const { - if (pixmap) + LyXImage * pixmap = 0; + + if (cacheHandle && (pixmap = cacheHandle->getImage())) return pixmap->getWidth(); else { char const * msg = statusMessage(); @@ -261,17 +265,13 @@ // This will draw the graphics. If the graphics has not been loaded yet, // we draw just a rectangle. - if (pixmap) { + if (imageLoaded) { paint.image(int(old_x) + 2, baseline - lascent, lwidth - 4, lascent + ldescent, - pixmap); + cacheHandle->getImage()); } else { #ifdef INSETGRAPHICS_INLINE_VIEW - if (!updateImage) { - updateImage = true; - updateInset(); - } // Get the image status, default to unknown error. GraphicsCacheItem::ImageStatus status = GraphicsCacheItem::UnknownError; @@ -280,8 +280,7 @@ // Check if the image is now ready. if (status == GraphicsCacheItem::Loaded) { - // It is, get it and inform the world. - pixmap = cacheHandle->getImage(); + imageLoaded = true; // Tell BufferView we need to be updated! bv->text->status = LyXText::CHANGED_IN_DRAW; @@ -450,8 +449,12 @@ string outfile; if (!buf->niceFile) { + lyxerr << "buf::tmppath = " << buf->tmppath << "\n"; + lyxerr << "filename = " << params.filename << "\n"; string const temp = AddName(buf->tmppath, params.filename); outfile = RemoveExtension(temp); + lyxerr << "temp = " << temp << "\n"; + lyxerr << "outfile = " << outfile << endl; } else { string const path = OnlyPath(buf->fileName()); string const relname = MakeRelPath(params.filename, path); @@ -581,21 +584,18 @@ // dialog. void InsetGraphics::updateInset() const { -#ifdef INSETGRAPHICS_INLINE_VIEW - if (updateImage) { - GraphicsCache * gc = GraphicsCache::getInstance(); - GraphicsCacheItem * temp = 0; - - if (!params.filename.empty()) { - temp = gc->addFile(params.filename); - } + GraphicsCache * gc = GraphicsCache::getInstance(); + GraphicsCacheItem * temp = 0; - delete cacheHandle; - cacheHandle = temp; + if (!params.filename.empty()) { + temp = gc->addFile(params.filename); } -#else - cacheHandle = 0; -#endif + + // Mark the image as unloaded so that it gets updated. + imageLoaded = false; + + delete cacheHandle; + cacheHandle = temp; } bool InsetGraphics::setParams(InsetGraphicsParams const & params) @@ -627,8 +627,7 @@ newInset->cacheHandle = cacheHandle->Clone(); else newInset->cacheHandle = 0; - newInset->pixmap = pixmap; - newInset->updateImage = updateImage; + newInset->imageLoaded = imageLoaded; newInset->setParams(getParams()); Index: src/insets/insetgraphics.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.h,v retrieving revision 1.25 diff -u -r1.25 insetgraphics.h --- src/insets/insetgraphics.h 2001/02/08 13:06:55 1.25 +++ src/insets/insetgraphics.h 2001/02/18 19:36:08 @@ -114,10 +114,8 @@ /// The graphics cache handle. mutable GraphicsCacheItem * cacheHandle; - /// The pixmap - mutable LyXImage * pixmap; /// is the pixmap initialized? - mutable bool updateImage; + mutable bool imageLoaded; InsetGraphicsParams params; };