]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.C
Baruch's patch + some fixes to it.
[lyx.git] / src / graphics / GraphicsCacheItem.C
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995 Matthias Ettrich.
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  *          This file Copyright 2000 Baruch Even
10  * ================================================= */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "graphics/GraphicsCache.h"
19 #include "graphics/GraphicsCacheItem.h"
20 #include "graphics/GraphicsCacheItem_pimpl.h"
21
22 GraphicsCacheItem::GraphicsCacheItem()
23         : pimpl(new GraphicsCacheItem_pimpl)
24 {
25         pimpl->refCount = 1;
26 }
27
28 GraphicsCacheItem::~GraphicsCacheItem()
29 {
30         destroy();
31 }
32
33 bool
34 GraphicsCacheItem::setFilename(string const & filename)
35 {
36         filename_ = filename;
37         return pimpl->setFilename(filename);
38 }
39
40 GraphicsCacheItem::GraphicsCacheItem(GraphicsCacheItem const & gci)
41 {
42         pimpl = 0;
43         copy(gci);
44 }
45
46 GraphicsCacheItem const &
47 GraphicsCacheItem::operator=(GraphicsCacheItem const & gci)
48 {
49         // Are we trying to copy the object onto itself.
50         if (this == &gci)
51                 return *this;
52
53         // Destory old copy 
54         destroy();
55
56         // And then copy new object.
57         copy(gci);
58
59         return *this;
60 }
61
62 void
63 GraphicsCacheItem::copy(GraphicsCacheItem const & gci)
64 {
65         pimpl = gci.pimpl;
66         ++(pimpl->refCount);
67 }
68
69 void
70 GraphicsCacheItem::destroy()
71 {
72         if (pimpl) {
73                 --(pimpl->refCount);
74                 if (pimpl->refCount == 0) {
75                         delete pimpl;
76                         GraphicsCache * gc = GraphicsCache::getInstance();
77                         gc->removeFile(filename_);
78                 }
79         }
80 }
81
82 GraphicsCacheItem::ImageStatus 
83 GraphicsCacheItem::getImageStatus() const { return pimpl->imageStatus_; }
84
85 int 
86 GraphicsCacheItem::getHeight() const { return pimpl->height_; } 
87         
88 int 
89 GraphicsCacheItem::getWidth() const { return pimpl->width_; }
90
91 Pixmap 
92 GraphicsCacheItem::getImage() const { return pimpl->pixmap_; }