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