]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
997d3ad804b8adde8a79db1f3991782c6cd6cf13
[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         void metrics(MetricsInfo &, Dimension &) const;
37         ///
38         EDITABLE editable() const;
39         ///
40         void write(Buffer const &, std::ostream &) const;
41         ///
42         void read(Buffer const &, LyXLex & lex);
43
44         /** returns the number of rows (\n's) of generated tex code.
45          #fragile == true# means, that the inset should take care about
46          fragile commands by adding a #\protect# before.
47          */
48         int latex(Buffer const &, std::ostream &,
49                   LatexRunParams const &) const;
50         ///
51         int ascii(Buffer const &, std::ostream &,
52                   LatexRunParams const &) const;
53         ///
54         int linuxdoc(Buffer const &, std::ostream &,
55                      LatexRunParams const &) const;
56         ///
57         int docbook(Buffer const &, std::ostream &,
58                     LatexRunParams const &) const;
59
60         /** Tell LyX what the latex features you need i.e. what latex packages
61             you need to be included.
62          */
63         void validate(LaTeXFeatures & features) const;
64
65         /// returns LyX code associated with the inset. Used for TOC, ...)
66         InsetOld::Code lyxCode() const { return InsetOld::GRAPHICS_CODE; }
67
68         ///
69         virtual std::auto_ptr<InsetBase> clone() const;
70
71         /** Set the inset parameters, used by the GUIndependent dialog.
72             Return true of new params are different from what was so far.
73         */
74         bool setParams(InsetGraphicsParams const & params);
75
76         /// Get the inset parameters, used by the GUIndependent dialog.
77         InsetGraphicsParams const & params() const;
78         ///
79         void draw(PainterInfo & pi, int x, int y) const;
80         ///
81         void edit(BufferView * bv, bool);
82 protected:
83         ///
84         virtual
85         DispatchResult
86         priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
87 private:
88         ///
89         friend class InsetGraphicsMailer;
90
91         /** This method is connected to the graphics loader, so we are
92          *  informed when the image has been loaded.
93          */
94         void statusChanged() const;
95
96         /// Read the inset native format
97         void readInsetGraphics(LyXLex & lex, std::string const & bufpath);
98
99         /// Get the status message, depends on the image loading status.
100         std::string const statusMessage() const;
101         /// Create the options for the latex command.
102         std::string const createLatexOptions() const;
103         /// Convert the file if needed, and return the location of the file.
104         std::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         std::string const graphic_label;
111
112         /// The thing that actually draws the image on LyX's screen.
113         boost::scoped_ptr<RenderGraphic> const graphic_;
114 };
115
116
117 #include "mailinset.h"
118
119 class InsetGraphicsMailer : public MailInset {
120 public:
121         ///
122         InsetGraphicsMailer(InsetGraphics & inset);
123         ///
124         virtual InsetBase & inset() const { return inset_; }
125         ///
126         virtual std::string const & name() const { return name_; }
127         ///
128         virtual std::string const inset2string(Buffer const &) const;
129         ///
130         static void string2params(std::string const & data,
131                                   Buffer const & buffer,
132                                   InsetGraphicsParams &);
133         ///
134         static std::string const params2string(InsetGraphicsParams const &,
135                                           Buffer const &);
136 private:
137         ///
138         static std::string const name_;
139         ///
140         InsetGraphics & inset_;
141 };
142
143 #endif