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(std::ostream &) const;
43 void read(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(odocstream &, OutputParams const &) const;
51 int plaintext(odocstream &, OutputParams const &) const;
53 int docbook(odocstream &, OutputParams const &) const;
55 /** Tell LyX what the latex features you need i.e. what latex packages
56 you need to be included.
58 void validate(LaTeXFeatures & features) const;
60 /// returns LyX code associated with the inset. Used for TOC, ...)
61 InsetCode lyxCode() const { return GRAPHICS_CODE; }
63 /** Set the inset parameters, used by the GUIndependent dialog.
64 Return true of new params are different from what was so far.
66 bool setParams(InsetGraphicsParams const & params);
68 /// Get the inset parameters, used by the GUIndependent dialog.
69 InsetGraphicsParams const & params() const;
71 void draw(PainterInfo & pi, int x, int y) const;
73 void edit(Cursor & cur, bool front, EntryDirection entry_from);
75 void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
77 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
78 /// all graphics can be embedded
79 void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const;
81 void updateEmbeddedFile(Buffer const &, EmbeddedFile const &);
82 /// Force inset into LTR environment if surroundings are RTL?
83 virtual bool forceLTR() const { return true; }
85 InsetGraphics(InsetGraphics const &);
87 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
89 friend class InsetGraphicsMailer;
91 virtual Inset * clone() const;
93 /// Read the inset native format
94 void readInsetGraphics(Lexer & lex, std::string const & bufpath);
96 /// Get the status message, depends on the image loading status.
97 std::string const statusMessage() const;
98 /// Create the options for the latex command.
99 std::string const createLatexOptions() const;
100 /// Create length values for docbook export.
101 docstring const toDocbookLength(Length const & len) const;
102 /// Create the atributes for docbook export.
103 docstring const createDocBookAttributes() const;
104 /// Convert the file if needed, and return the location of the file.
105 std::string prepareFile(OutputParams const &) const;
108 InsetGraphicsParams params_;
110 /// holds the entity name that defines the graphics location (SGML).
111 docstring const graphic_label;
113 /// The thing that actually draws the image on LyX's screen.
114 boost::scoped_ptr<RenderGraphic> const graphic_;
118 class InsetGraphicsMailer : public MailInset {
121 InsetGraphicsMailer(InsetGraphics & inset);
123 virtual Inset & inset() const { return inset_; }
125 virtual std::string const & name() const { return name_; }
127 virtual std::string const inset2string(Buffer const &) const;
129 static void string2params(std::string const & data,
130 Buffer const & buffer,
131 InsetGraphicsParams &);
133 static std::string const params2string(InsetGraphicsParams const &,
137 static std::string const name_;
139 InsetGraphics & inset_;