]> git.lyx.org Git - lyx.git/blob - src/insets/renderers.h
Enable convertDefault.sh to run even if its executable bit is not set.
[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 "dimension.h"
16
17 #include "graphics/GraphicsLoader.h"
18 #include "graphics/GraphicsParams.h"
19 #include "graphics/GraphicsTypes.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 private:
72         /// The stored data.
73         string text_;
74         bool editable_;
75 };
76
77
78 class GraphicRenderer : public RenderInset
79 {
80 public:
81         GraphicRenderer();
82         GraphicRenderer(GraphicRenderer const &);
83
84         virtual RenderInset * clone() const;
85
86         /// Refresh the info about which file to display and how to display it.
87         void update(lyx::graphics::Params const & params);
88
89         /// compute the size of the object returned in dim
90         virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
91         /// draw inset and update (xo, yo)-cache
92         virtual void draw(PainterInfo & pi, int x, int y) const;
93
94         /// Is the stored checksum different to that of the graphics loader?
95         bool hasFileChanged() const;
96
97         /** Connect and you'll be informed when the loading status of the image
98          *  changes.
99          */
100         typedef boost::signal0<void>::slot_type slot_type;
101         virtual boost::signals::connection connect(slot_type const &) const;
102
103 private:
104         /// Not implemented.
105         GraphicRenderer & operator=(GraphicRenderer const &);
106
107         /// The message to display instead of the graphic itself.
108         string const statusMessage() const;
109
110         /// Is the image ready to draw, or should we display a message instead?
111         bool readyToDisplay() const;
112
113         /// The stored data.
114         lyx::graphics::Loader loader_;
115         lyx::graphics::Params params_;
116
117         /// Cached variable (not copied).
118         mutable unsigned long checksum_;
119 };
120
121
122 #endif // NOT RENDERERS_H