]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
clone() at long last !
[lyx.git] / src / insets / insetgraphics.h
1 // -*- C++ -*-
2 /**
3  * \file insetgraphics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  * \author Herbert Voss
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #ifndef INSET_GRAPHICS_H
14 #define INSET_GRAPHICS_H
15
16 #include "inset.h"
17 #include "insetgraphicsParams.h"
18 #include "dimension.h"
19
20 #include <boost/signals/trackable.hpp>
21 #include <boost/scoped_ptr.hpp>
22
23 class Dialogs;
24 class LaTeXFeatures;
25
26 ///
27 class InsetGraphics : public Inset, public boost::signals::trackable {
28 public:
29         ///
30         InsetGraphics();
31         ///
32         InsetGraphics(InsetGraphics const &);
33         ///
34         ~InsetGraphics();
35         ///
36         virtual dispatch_result localDispatch(FuncRequest const & cmd);
37         ///
38         void metrics(MetricsInfo &, Dimension &) const;
39         ///
40         void draw(PainterInfo & pi, int x, int y) const;
41         ///
42         EDITABLE editable() const;
43         ///
44         void write(Buffer const *, std::ostream &) const;
45         ///
46         void read(Buffer const *, LyXLex & lex);
47
48         /** returns the number of rows (\n's) of generated tex code.
49          #fragile == true# means, that the inset should take care about
50          fragile commands by adding a #\protect# before.
51          */
52         int latex(Buffer const *, std::ostream &,
53                   LatexRunParams const &) const;
54         ///
55         int ascii(Buffer const *, std::ostream &, int linelen) const;
56         ///
57         int linuxdoc(Buffer const *, std::ostream &) const;
58         ///
59         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
60
61         /** Tell LyX what the latex features you need i.e. what latex packages
62             you need to be included.
63          */
64         void validate(LaTeXFeatures & features) const;
65
66         /// returns LyX code associated with the inset. Used for TOC, ...)
67         Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
68
69         ///
70         virtual Inset * clone() const;
71
72         /** Set the inset parameters, used by the GUIndependent dialog.
73             Return true of new params are different from what was so far.
74         */
75         bool setParams(InsetGraphicsParams const & params);
76
77         /// Get the inset parameters, used by the GUIndependent dialog.
78         InsetGraphicsParams const & params() const;
79
80 private:
81         /// Returns the cached BufferView.
82         BufferView * view() const;
83
84         ///
85         friend class InsetGraphicsMailer;
86
87         /// Is the image ready to draw, or should we display a message instead?
88         bool imageIsDrawable() const;
89
90         /** This method is connected to cache_->statusChanged, so we are
91             informed when the image has been loaded.
92          */
93         void statusChanged();
94
95         /// Read the inset native format
96         void readInsetGraphics(LyXLex & lex, string const & bufpath);
97
98         /// Get the status message, depends on the image loading status.
99         string const statusMessage() const;
100         /// Create the options for the latex command.
101         string const createLatexOptions() const;
102         /// Convert the file if needed, and return the location of the file.
103         string const prepareFile(Buffer const * buf, LatexRunParams const &) const;
104
105         ///
106         InsetGraphicsParams params_;
107
108         /// holds the entity name that defines the graphics location (SGML).
109         string const graphic_label;
110
111         /// The cached variables
112         class Cache;
113         friend class Cache;
114         /// The pointer never changes although *cache_'s contents may.
115         boost::scoped_ptr<Cache> const cache_;
116         /// dimension cache
117         mutable Dimension dim_;
118 };
119
120
121 #include "mailinset.h"
122
123 class InsetGraphicsMailer : public MailInset {
124 public:
125         ///
126         InsetGraphicsMailer(InsetGraphics & inset);
127         ///
128         virtual InsetBase & inset() const { return inset_; }
129         ///
130         virtual string const & name() const { return name_; }
131         ///
132         virtual string const inset2string() const;
133         ///
134         static void string2params(string const &, InsetGraphicsParams &);
135         ///
136         static string const params2string(InsetGraphicsParams const &);
137 private:
138         ///
139         static string const name_;
140         ///
141         InsetGraphics & inset_;
142 };
143
144 #endif