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