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