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