]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
Rename LatexRunParams::fragile as moving_arg.
[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 "insets/inset.h"
17 #include "insets/insetgraphicsParams.h"
18
19 #include <boost/signals/trackable.hpp>
20 #include <boost/scoped_ptr.hpp>
21
22 class Dialogs;
23 class LaTeXFeatures;
24
25 ///
26 class InsetGraphics : public Inset, public boost::signals::trackable {
27 public:
28         ///
29         InsetGraphics();
30         ///
31         InsetGraphics(InsetGraphics const &, string const & filepath,
32                       bool same_id = false);
33         ///
34         ~InsetGraphics();
35         ///
36         virtual dispatch_result localDispatch(FuncRequest const & cmd);
37         ///
38         void dimension(BufferView *, LyXFont const &, Dimension &) const;
39         ///
40         void draw(BufferView *, LyXFont const &, int, float &) 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(Buffer const &, bool same_id = false) 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                        string const & filepath);
77
78         /// Get the inset parameters, used by the GUIndependent dialog.
79         InsetGraphicsParams const & params() const;
80
81 private:
82         /// Returns the cached BufferView.
83         BufferView * view() const;
84
85         ///
86         friend class InsetGraphicsMailer;
87
88         /// Is the image ready to draw, or should we display a message instead?
89         bool imageIsDrawable() const;
90
91         /** This method is connected to cache_->statusChanged, so we are
92             informed when the image has been loaded.
93          */
94         void statusChanged();
95
96         /// Read the inset native format
97         void readInsetGraphics(LyXLex & lex);
98
99         /// Get the status message, depends on the image loading status.
100         string const statusMessage() const;
101         /// Create the options for the latex command.
102         string const createLatexOptions() const;
103         /// Convert the file if needed, and return the location of the file.
104         string const prepareFile(Buffer const * buf, LatexRunParams const &) const;
105
106         ///
107         InsetGraphicsParams params_;
108
109         /// holds the entity name that defines the graphics location (SGML).
110         string const graphic_label;
111
112         /// The cached variables
113         class Cache;
114         friend class Cache;
115         /// The pointer never changes although *cache_'s contents may.
116         boost::scoped_ptr<Cache> const cache_;
117 };
118
119
120 #include "mailinset.h"
121
122 class InsetGraphicsMailer : public MailInset {
123 public:
124         ///
125         InsetGraphicsMailer(InsetGraphics & inset);
126         ///
127         virtual InsetBase & inset() const { return inset_; }
128         ///
129         virtual string const & name() const { return name_; }
130         ///
131         virtual string const inset2string() const;
132         ///
133         static void string2params(string const &, InsetGraphicsParams &);
134         ///
135         static string const params2string(InsetGraphicsParams const &);
136 private:
137         ///
138         static string const name_;
139         ///
140         InsetGraphics & inset_;
141 };
142
143 #endif