]> git.lyx.org Git - lyx.git/blob - src/insets/InsetGraphics.h
b1270bb30c321d9b2fe4f4e94703a30968ac9b78
[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 Voß
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 "MailInset.h"
19
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signals/trackable.hpp>
22
23
24 namespace lyx {
25
26 class RenderGraphic;
27 class LaTeXFeatures;
28
29 ///
30 class InsetGraphics : public Inset, public boost::signals::trackable {
31 public:
32         ///
33         InsetGraphics();
34         ///
35         ~InsetGraphics();
36         ///
37         bool isLabeled() const { return true; }
38         void metrics(MetricsInfo &, Dimension &) const;
39         ///
40         EDITABLE editable() const;
41         ///
42         void write(std::ostream &) const;
43         ///
44         void read(Lexer & lex);
45
46         /** returns the number of rows (\n's) of generated tex code.
47          #fragile == true# means, that the inset should take care about
48          fragile commands by adding a #\protect# before.
49          */
50         int latex(odocstream &, OutputParams const &) const;
51         ///
52         int plaintext(odocstream &, OutputParams const &) const;
53         ///
54         int docbook(odocstream &, OutputParams const &) const;
55
56         /** Tell LyX what the latex features you need i.e. what latex packages
57             you need to be included.
58          */
59         void validate(LaTeXFeatures & features) const;
60
61         /// returns LyX code associated with the inset. Used for TOC, ...)
62         InsetCode lyxCode() const { return GRAPHICS_CODE; }
63
64         /** Set the inset parameters, used by the GUIndependent dialog.
65             Return true of new params are different from what was so far.
66         */
67         bool setParams(InsetGraphicsParams const & params);
68
69         /// Get the inset parameters, used by the GUIndependent dialog.
70         InsetGraphicsParams const & params() const;
71         ///
72         void draw(PainterInfo & pi, int x, int y) const;
73         ///
74         void edit(Cursor & cur, bool front, EntryDirection entry_from);
75         ///
76         void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
77         ///
78         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
79         /// all graphics can be embedded
80         void registerEmbeddedFiles(EmbeddedFileList &) const;
81         ///
82         void updateEmbeddedFile(EmbeddedFile const &);
83         ///
84         void addToToc(ParConstIterator const &) const;
85
86         /// Force inset into LTR environment if surroundings are RTL?
87         virtual bool forceLTR() const { return true; }
88 protected:
89         InsetGraphics(InsetGraphics const &);
90         ///
91         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
92 private:
93         friend class InsetGraphicsMailer;
94
95         virtual Inset * clone() const;
96
97         /// Read the inset native format
98         void readInsetGraphics(Lexer & lex, std::string const & bufpath);
99
100         /// Get the status message, depends on the image loading status.
101         std::string const statusMessage() const;
102         /// Create the options for the latex command.
103         std::string const createLatexOptions() const;
104         /// Create length values for docbook export.
105         docstring const toDocbookLength(Length const & len) const;
106         /// Create the atributes for docbook export.
107         docstring const createDocBookAttributes() const;
108         /// Convert the file if needed, and return the location of the file.
109         std::string prepareFile(OutputParams const &) const;
110
111         ///
112         InsetGraphicsParams params_;
113
114         /// holds the entity name that defines the graphics location (SGML).
115         docstring const graphic_label;
116
117         /// The thing that actually draws the image on LyX's screen.
118         boost::scoped_ptr<RenderGraphic> const graphic_;
119 };
120
121
122 class InsetGraphicsMailer : public MailInset {
123 public:
124         ///
125         InsetGraphicsMailer(InsetGraphics & inset);
126         ///
127         virtual Inset & inset() const { return inset_; }
128         ///
129         virtual std::string const & name() const { return name_; }
130         ///
131         virtual std::string const inset2string(Buffer const &) const;
132         ///
133         static void string2params(std::string const & data,
134                                   Buffer const & buffer,
135                                   InsetGraphicsParams &);
136         ///
137         static std::string const params2string(InsetGraphicsParams const &,
138                                           Buffer const &);
139 private:
140         ///
141         static std::string const name_;
142         ///
143         InsetGraphics & inset_;
144 };
145
146
147 } // namespace lyx
148
149 #endif