]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.C
prepare for 1.1.6pre2
[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 #include "frontends/support/LyXImage.h"
22
23
24 GraphicsCacheItem::GraphicsCacheItem()
25         : pimpl(new GraphicsCacheItem_pimpl)
26 {
27         pimpl->refCount = 1;
28 }
29
30
31 GraphicsCacheItem::~GraphicsCacheItem()
32 {
33         destroy();
34 }
35
36
37 bool
38 GraphicsCacheItem::setFilename(string const & filename)
39 {
40         filename_ = filename;
41         return pimpl->setFilename(filename);
42 }
43
44
45 GraphicsCacheItem::GraphicsCacheItem(GraphicsCacheItem const & gci)
46 {
47         pimpl = 0;
48         copy(gci);
49 }
50
51 GraphicsCacheItem &
52 GraphicsCacheItem::operator=(GraphicsCacheItem const & gci)
53 {
54         // Are we trying to copy the object onto itself.
55         if (this == &gci)
56                 return *this;
57
58         // Destroy old copy 
59         destroy();
60
61         // And then copy new object.
62         copy(gci);
63
64         return *this;
65 }
66
67 GraphicsCacheItem *
68 GraphicsCacheItem::Clone() const
69 {
70         return new GraphicsCacheItem(*this);
71 }
72
73 void
74 GraphicsCacheItem::copy(GraphicsCacheItem const & gci)
75 {
76         pimpl = gci.pimpl;
77         ++(pimpl->refCount);
78 }
79
80
81 void
82 GraphicsCacheItem::destroy()
83 {
84         if (pimpl) {
85                 --(pimpl->refCount);
86                 if (pimpl->refCount == 0) {
87                         {   // We are deleting the pimpl but we want to mark it deleted
88                                 // even before it is deleted.
89                                 GraphicsCacheItem_pimpl * temp = pimpl;
90                                 pimpl = 0;
91                                 delete temp; 
92                         }
93                         GraphicsCache * gc = GraphicsCache::getInstance();
94                         gc->removeFile(filename_);
95                 }
96         }
97 }
98
99
100 GraphicsCacheItem::ImageStatus 
101 GraphicsCacheItem::getImageStatus() const { return pimpl->imageStatus_; }
102
103
104 int 
105 GraphicsCacheItem::getHeight() const { return pimpl->height_; } 
106
107
108 int 
109 GraphicsCacheItem::getWidth() const { return pimpl->width_; }
110
111 LyXImage * 
112 GraphicsCacheItem::getImage() const { return pimpl->pixmap_; }