]> git.lyx.org Git - lyx.git/blob - src/insets/graphicinset.h
Small clean-ups.
[lyx.git] / src / insets / graphicinset.h
1 // -*- C++ -*-
2 /**
3  * \file graphicinset.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 GRAPHICINSET_H
13 #define GRAPHICINSET_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 GraphicInset
31 {
32 public:
33         GraphicInset();
34         GraphicInset(GraphicInset const &);
35
36         /** Set the message that the inset will show when the
37          *  display of the graphic is deactivated.
38          *  The default is nothing, meaning that the inset will
39          *  show a message descibing the state of the image
40          *  loading process.
41          */
42         void setNoDisplayMessage(string const & msg);
43         
44         /// Refresh the info about which file to display and how to display it.
45         void update(grfx::Params const & params);
46
47         /// compute the size of the object returned in dim
48         void metrics(MetricsInfo & mi, Dimension & dim) const;
49         /// draw inset and update (xo, yo)-cache
50         void draw(PainterInfo & pi, int x, int y) const;
51
52         /// Is the stored checksum different to that of the graphics loader?
53         bool hasFileChanged() const;
54         /// Set the cached store.
55         void view(BufferView *) const;
56         /// An accessor function to the cached store.
57         BufferView * view() const;
58
59         /** Connect and you'll be informed when the loading status of the image
60          *  changes.
61          */
62         typedef boost::signal0<void>::slot_type slot_type;
63         boost::signals::connection connect(slot_type const &) const;
64
65 private:
66         /// Not implemented.
67         GraphicInset & operator=(GraphicInset const &);
68
69         /// The message to display instead of the graphic itself.
70         string const statusMessage() const;
71
72         enum DisplayType {
73                 IMAGE,
74                 STATUS_MESSAGE,
75                 NODISPLAY_MESSAGE
76         };
77
78         /// Is the image ready to draw, or should we display a message instead?
79         DisplayType displayType() const;
80         
81         /// The stored data.
82         grfx::Loader loader_;
83         grfx::Params params_;
84         string nodisplay_message_;
85
86         /// These are all cached variables.
87         mutable unsigned long checksum_;
88         mutable boost::weak_ptr<BufferView> view_;
89         mutable Dimension dim_;
90 };
91
92
93 #endif // NOT GRAPHICINSET_H