2000-07-31 12:30:10 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* =================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
* Copyright 1995 Matthias Ettrich.
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* This file Copyright 2000 Baruch Even
|
|
|
|
* ================================================= */
|
|
|
|
|
2000-07-31 16:39:50 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
#include "graphics/GraphicsCache.h"
|
|
|
|
#include "graphics/GraphicsCacheItem.h"
|
|
|
|
#include "graphics/GraphicsCacheItem_pimpl.h"
|
2000-10-12 10:46:06 +00:00
|
|
|
#include "frontends/support/LyXImage.h"
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
GraphicsCacheItem::GraphicsCacheItem()
|
2000-08-10 13:15:05 +00:00
|
|
|
: pimpl(new GraphicsCacheItem_pimpl)
|
|
|
|
{
|
|
|
|
pimpl->refCount = 1;
|
|
|
|
}
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
GraphicsCacheItem::~GraphicsCacheItem()
|
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
destroy();
|
2000-08-08 09:18:39 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
bool
|
|
|
|
GraphicsCacheItem::setFilename(string const & filename)
|
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
filename_ = filename;
|
|
|
|
return pimpl->setFilename(filename);
|
2000-08-08 09:18:39 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
GraphicsCacheItem::GraphicsCacheItem(GraphicsCacheItem const & gci)
|
2000-08-08 09:18:39 +00:00
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
pimpl = 0;
|
|
|
|
copy(gci);
|
2000-08-08 09:18:39 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
GraphicsCacheItem &
|
2000-08-10 13:15:05 +00:00
|
|
|
GraphicsCacheItem::operator=(GraphicsCacheItem const & gci)
|
2000-08-08 09:18:39 +00:00
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
// Are we trying to copy the object onto itself.
|
|
|
|
if (this == &gci)
|
|
|
|
return *this;
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
// Destroy old copy
|
2000-08-10 13:15:05 +00:00
|
|
|
destroy();
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
// And then copy new object.
|
|
|
|
copy(gci);
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-10-12 10:46:06 +00:00
|
|
|
GraphicsCacheItem *
|
|
|
|
GraphicsCacheItem::Clone() const
|
|
|
|
{
|
|
|
|
return new GraphicsCacheItem(*this);
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
void
|
|
|
|
GraphicsCacheItem::copy(GraphicsCacheItem const & gci)
|
2000-08-08 09:18:39 +00:00
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
pimpl = gci.pimpl;
|
|
|
|
++(pimpl->refCount);
|
2000-08-08 09:18:39 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-08 09:18:39 +00:00
|
|
|
void
|
2000-08-10 13:15:05 +00:00
|
|
|
GraphicsCacheItem::destroy()
|
2000-08-08 09:18:39 +00:00
|
|
|
{
|
2000-08-10 13:15:05 +00:00
|
|
|
if (pimpl) {
|
|
|
|
--(pimpl->refCount);
|
|
|
|
if (pimpl->refCount == 0) {
|
2000-10-12 10:46:06 +00:00
|
|
|
{ // 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;
|
|
|
|
}
|
2000-08-10 13:15:05 +00:00
|
|
|
GraphicsCache * gc = GraphicsCache::getInstance();
|
|
|
|
gc->removeFile(filename_);
|
|
|
|
}
|
2000-08-08 09:18:39 +00:00
|
|
|
}
|
2000-08-10 13:15:05 +00:00
|
|
|
}
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
GraphicsCacheItem::ImageStatus
|
|
|
|
GraphicsCacheItem::getImageStatus() const { return pimpl->imageStatus_; }
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
int
|
|
|
|
GraphicsCacheItem::getHeight() const { return pimpl->height_; }
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
|
|
|
2000-08-10 13:15:05 +00:00
|
|
|
int
|
|
|
|
GraphicsCacheItem::getWidth() const { return pimpl->width_; }
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2000-10-12 10:46:06 +00:00
|
|
|
LyXImage *
|
2000-08-10 13:15:05 +00:00
|
|
|
GraphicsCacheItem::getImage() const { return pimpl->pixmap_; }
|