]> git.lyx.org Git - features.git/blob - src/graphics/GraphicsCacheItem.h
Baruch's graphic-inset patch.
[features.git] / src / graphics / GraphicsCacheItem.h
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 #ifndef GRAPHICSCACHEITEM_H
13 #define GRAPHICSCACHEITEM_H
14
15 #include <config.h>
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include XPM_H_LOCATION
22 #include "LString.h"
23 #include "graphics/Renderer.h"
24 #include "support/syscall.h"
25
26 #include "sigc++/signal_system.h"
27 #ifdef SIGC_CXX_NAMESPACES
28 using SigC::Signal0;
29 #endif
30
31 /* (Baruch Even 2000-08-05)
32  * This has a major drawback: it is only designed for X servers, no easy
33  * porting to non X-server based platform is offered right now, this is done
34  * in order to get a first version out of the door.
35  *
36  * Later versions should consider how to do this with more platform 
37  * independence, this will probably involve changing the Painter class too.
38  */
39
40 /* (Baruch Even 2000-08-05)
41  * This should be made reference counted, but for the sake of initial design
42  * I'll forego that and just make a first version that actually works, though
43  * it may fail or leak in real document, this is an initial design to try
44  * ideas on and be a testbed.
45  * It may just as well be scraped later on to create a better design based on
46  * the results of working with the current design.
47  */
48
49 /// A GraphicsCache item holder.
50 class GraphicsCacheItem {
51 public:
52         /// d-tor, frees the image structures.
53         ~GraphicsCacheItem();
54         
55         /// Get the height of the image. Returns -1 on error.
56         int getHeight() const { return height_; }       
57         
58         /// Get the width of the image. Returns -1 on error.
59         int getWidth() const { return width_; }
60
61         /// Return a pixmap that can be displayed on X server.
62         Pixmap getImage() const { return pixmap_; }
63
64         enum ImageStatus {
65                 Loading = 1,
66                 ErrorConverting,
67                 ErrorReading,
68                 Loaded
69         };
70         
71         /// Is the pixmap ready for display?
72         ImageStatus getImageStatus() const { return imageStatus_; }
73
74         /// Get a notification when the image conversion is done.
75         /// used by an internal callback mechanism.
76         void imageConverted(int retval);
77
78         /// A signal objects can connect to in order to know when the image
79         /// has arrived.
80         Signal0<void> imageDone;
81 private:
82     /// Private c-tor so that only GraphicsCache can create an instance.
83     GraphicsCacheItem();
84
85         /// Set the filename this item will be pointing too.
86         bool setFilename(string const & filename);
87
88         /// Create an XPM file version of the image.
89         bool renderXPM(string const & filename);
90
91         /// Load the image from XPM to memory Pixmap
92         void loadXPMImage();
93         
94     ///
95     friend class GraphicsCache;
96
97         /// The file name of the XPM file.
98         string xpmfile;
99         /// The image height
100         int height_;
101         /// The image width
102         int width_;
103         /// Is the pixmap loaded?
104         ImageStatus imageStatus_;
105         /// The image pixmap
106         Pixmap pixmap_;
107         /// The rendering object.
108         Renderer * renderer;
109
110         /// The system caller, runs the convertor.
111         Systemcalls syscall;
112 };
113
114 #endif