3 * \file InsetGraphics.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSET_GRAPHICS_H
14 #define INSET_GRAPHICS_H
17 #include "InsetGraphicsParams.h"
18 #include "MailInset.h"
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signals/trackable.hpp>
30 class InsetGraphics : public Inset, public boost::signals::trackable {
37 void metrics(MetricsInfo &, Dimension &) const;
39 EDITABLE editable() const;
41 void write(Buffer const &, std::ostream &) const;
43 void read(Buffer const &, Lexer & lex);
45 /** returns the number of rows (\n's) of generated tex code.
46 #fragile == true# means, that the inset should take care about
47 fragile commands by adding a #\protect# before.
49 int latex(Buffer const &, odocstream &,
50 OutputParams const &) const;
52 int plaintext(Buffer const &, odocstream &,
53 OutputParams const &) const;
55 int docbook(Buffer const &, odocstream &,
56 OutputParams const &) const;
58 /** Tell LyX what the latex features you need i.e. what latex packages
59 you need to be included.
61 void validate(LaTeXFeatures & features) const;
63 /// returns LyX code associated with the inset. Used for TOC, ...)
64 InsetCode lyxCode() const { return GRAPHICS_CODE; }
66 /** Set the inset parameters, used by the GUIndependent dialog.
67 Return true of new params are different from what was so far.
69 bool setParams(InsetGraphicsParams const & params);
71 /// Get the inset parameters, used by the GUIndependent dialog.
72 InsetGraphicsParams const & params() const;
74 void draw(PainterInfo & pi, int x, int y) const;
76 void edit(Cursor & cur, bool left);
78 void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
80 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
81 /// all graphics can be embedded
82 void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const;
84 void updateEmbeddedFile(Buffer const &, EmbeddedFile const &);
85 /// Force inset into LTR environment if surroundings are RTL?
86 virtual bool forceLTR() const { return true; }
88 InsetGraphics(InsetGraphics const &);
90 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
92 friend class InsetGraphicsMailer;
94 virtual Inset * clone() const;
96 /// Read the inset native format
97 void readInsetGraphics(Lexer & lex, std::string const & bufpath);
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 /// Create length values for docbook export.
104 docstring const toDocbookLength(Length const & len) const;
105 /// Create the atributes for docbook export.
106 docstring const createDocBookAttributes() const;
107 /// Convert the file if needed, and return the location of the file.
108 std::string const prepareFile(Buffer const & buf, OutputParams const &) const;
111 InsetGraphicsParams params_;
113 /// holds the entity name that defines the graphics location (SGML).
114 docstring const graphic_label;
116 /// The thing that actually draws the image on LyX's screen.
117 boost::scoped_ptr<RenderGraphic> const graphic_;
121 class InsetGraphicsMailer : public MailInset {
124 InsetGraphicsMailer(InsetGraphics & inset);
126 virtual Inset & inset() const { return inset_; }
128 virtual std::string const & name() const { return name_; }
130 virtual std::string const inset2string(Buffer const &) const;
132 static void string2params(std::string const & data,
133 Buffer const & buffer,
134 InsetGraphicsParams &);
136 static std::string const params2string(InsetGraphicsParams const &,
140 static std::string const name_;
142 InsetGraphics & inset_;