]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
65597521424efd6c046942af26da74583ebdaa3b
[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
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/signals/trackable.hpp>
21
22 class Dialogs;
23 class RenderGraphic;
24 class LaTeXFeatures;
25
26 ///
27 class InsetGraphics : public InsetOld, 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         EDITABLE editable() const;
41         ///
42         void write(Buffer const &, std::ostream &) const;
43         ///
44         void read(Buffer const &, LyXLex & 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 &, std::ostream &,
51                   LatexRunParams const &) const;
52         ///
53         int ascii(Buffer const &, std::ostream &, int linelen) const;
54         ///
55         int linuxdoc(Buffer const &, std::ostream &) const;
56         ///
57         int docbook(Buffer const &, std::ostream &, bool mixcont) 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         InsetOld::Code lyxCode() const { return InsetOld::GRAPHICS_CODE; }
66
67         ///
68         virtual std::auto_ptr<InsetBase> clone() const;
69
70         /** Set the inset parameters, used by the GUIndependent dialog.
71             Return true of new params are different from what was so far.
72         */
73         bool setParams(InsetGraphicsParams const & params);
74
75         /// Get the inset parameters, used by the GUIndependent dialog.
76         InsetGraphicsParams const & params() const;
77         ///
78         void draw(PainterInfo & pi, int x, int y) const;
79
80 private:
81         ///
82         friend class InsetGraphicsMailer;
83
84         /** This method is connected to the graphics loader, so we are
85          *  informed when the image has been loaded.
86          */
87         void statusChanged() const;
88
89         /// Read the inset native format
90         void readInsetGraphics(LyXLex & lex, std::string const & bufpath);
91
92         /// Get the status message, depends on the image loading status.
93         std::string const statusMessage() const;
94         /// Create the options for the latex command.
95         std::string const createLatexOptions() const;
96         /// Convert the file if needed, and return the location of the file.
97         std::string const prepareFile(Buffer const & buf, LatexRunParams const &) const;
98
99         ///
100         InsetGraphicsParams params_;
101
102         /// holds the entity name that defines the graphics location (SGML).
103         std::string const graphic_label;
104
105         /// The thing that actually draws the image on LyX's screen.
106         boost::scoped_ptr<RenderGraphic> const graphic_;
107 };
108
109
110 #include "mailinset.h"
111
112 class InsetGraphicsMailer : public MailInset {
113 public:
114         ///
115         InsetGraphicsMailer(InsetGraphics & inset);
116         ///
117         virtual InsetBase & inset() const { return inset_; }
118         ///
119         virtual std::string const & name() const { return name_; }
120         ///
121         virtual std::string const inset2string(Buffer const &) const;
122         ///
123         static void string2params(std::string const & data,
124                                   Buffer const & buffer,
125                                   InsetGraphicsParams &);
126         ///
127         static std::string const params2string(InsetGraphicsParams const &,
128                                           Buffer const &);
129 private:
130         ///
131         static std::string const name_;
132         ///
133         InsetGraphics & inset_;
134 };
135
136 #endif