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