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