]> git.lyx.org Git - lyx.git/blob - src/insets/renderers.h
Re-add the RasterImage template.
[lyx.git] / src / insets / renderers.h
1 // -*- C++ -*-
2 /**
3  * \file renderers.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef RENDERERS_H
13 #define RENDERERS_H
14
15 #include "box.h"
16 #include "dimension.h"
17
18 #include "graphics/GraphicsLoader.h"
19 #include "graphics/GraphicsParams.h"
20
21 #include <boost/weak_ptr.hpp>
22 #include <boost/signals/signal0.hpp>
23
24
25 class BufferView;
26 class MetricsInfo;
27 class PainterInfo;
28
29
30 class RenderInset
31 {
32 public:
33         virtual ~RenderInset();
34
35         virtual RenderInset * clone() const = 0;
36
37         /// compute the size of the object returned in dim
38         virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
39         /// draw inset and update (xo, yo)-cache
40         virtual void draw(PainterInfo & pi, int x, int y) const = 0;
41
42         /// An accessor function to the cached store.
43         BufferView * view() const;
44
45 protected:
46         RenderInset();
47         RenderInset(RenderInset const &);
48         RenderInset & operator=(RenderInset const &);
49
50         /// These are cached variables (are not copied).
51         mutable boost::weak_ptr<BufferView> view_;
52         mutable Dimension dim_;
53 };
54
55
56 class ButtonRenderer : public RenderInset
57 {
58 public:
59         ButtonRenderer();
60
61         virtual RenderInset * clone() const;
62
63         /// This should provide the text for the button
64         void update(string const &, bool editable);
65
66         /// compute the size of the object returned in dim
67         virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
68         /// draw inset and update (xo, yo)-cache
69         virtual void draw(PainterInfo & pi, int x, int y) const;
70
71         /// The "sensitive area" box, i.e., the button area
72         Box box() const { return button_box_; }
73         ///
74         void setBox(Box b) { button_box_ = b; }
75
76 private:
77         /// The stored data.
78         string text_;
79         bool editable_;
80         Box button_box_;
81 };
82
83
84 class GraphicRenderer : public RenderInset
85 {
86 public:
87         GraphicRenderer();
88         GraphicRenderer(GraphicRenderer const &);
89
90         virtual RenderInset * clone() const;
91
92         /// Refresh the info about which file to display and how to display it.
93         void update(lyx::graphics::Params const & params);
94
95         /// compute the size of the object returned in dim
96         virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
97         /// draw inset and update (xo, yo)-cache
98         virtual void draw(PainterInfo & pi, int x, int y) const;
99
100         /// Is the stored checksum different to that of the graphics loader?
101         bool hasFileChanged() const;
102
103         /** Connect and you'll be informed when the loading status of the image
104          *  changes.
105          */
106         typedef boost::signal0<void>::slot_type slot_type;
107         virtual boost::signals::connection connect(slot_type const &) const;
108
109 private:
110         /// Not implemented.
111         GraphicRenderer & operator=(GraphicRenderer const &);
112
113         /// The message to display instead of the graphic itself.
114         string const statusMessage() const;
115
116         /// Is the image ready to draw, or should we display a message instead?
117         bool readyToDisplay() const;
118
119         /// The stored data.
120         lyx::graphics::Loader loader_;
121         lyx::graphics::Params params_;
122
123         /// Cached variable (not copied).
124         mutable unsigned long checksum_;
125 };
126
127
128 #endif // NOT RENDERERS_H