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 bool isLabeled() const { return true; }
38 void metrics(MetricsInfo &, Dimension &) const;
40 EDITABLE editable() const;
42 void write(std::ostream &) const;
44 void read(Lexer & lex);
46 /** returns the number of rows (\n's) of generated tex code.
47 #fragile == true# means, that the inset should take care about
48 fragile commands by adding a #\protect# before.
50 int latex(odocstream &, OutputParams const &) const;
52 int plaintext(odocstream &, OutputParams const &) const;
54 int docbook(odocstream &, OutputParams const &) const;
56 /** Tell LyX what the latex features you need i.e. what latex packages
57 you need to be included.
59 void validate(LaTeXFeatures & features) const;
61 /// returns LyX code associated with the inset. Used for TOC, ...)
62 InsetCode lyxCode() const { return GRAPHICS_CODE; }
64 /** Set the inset parameters, used by the GUIndependent dialog.
65 Return true of new params are different from what was so far.
67 bool setParams(InsetGraphicsParams const & params);
69 /// Get the inset parameters, used by the GUIndependent dialog.
70 InsetGraphicsParams const & params() const;
72 void draw(PainterInfo & pi, int x, int y) const;
74 void edit(Cursor & cur, bool front, EntryDirection entry_from);
76 void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
78 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
79 /// all graphics can be embedded
80 void registerEmbeddedFiles(EmbeddedFileList &) const;
82 void updateEmbeddedFile(EmbeddedFile const &);
84 void addToToc(ParConstIterator const &) const;
86 /// Force inset into LTR environment if surroundings are RTL?
87 virtual bool forceLTR() const { return true; }
89 InsetGraphics(InsetGraphics const &);
91 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
93 friend class InsetGraphicsMailer;
95 virtual Inset * clone() const;
97 /// Read the inset native format
98 void readInsetGraphics(Lexer & lex, std::string const & bufpath);
100 /// Get the status message, depends on the image loading status.
101 std::string const statusMessage() const;
102 /// Create the options for the latex command.
103 std::string const createLatexOptions() const;
104 /// Create length values for docbook export.
105 docstring const toDocbookLength(Length const & len) const;
106 /// Create the atributes for docbook export.
107 docstring const createDocBookAttributes() const;
108 /// Convert the file if needed, and return the location of the file.
109 std::string prepareFile(OutputParams const &) const;
112 InsetGraphicsParams params_;
114 /// holds the entity name that defines the graphics location (SGML).
115 docstring const graphic_label;
117 /// The thing that actually draws the image on LyX's screen.
118 boost::scoped_ptr<RenderGraphic> const graphic_;
122 class InsetGraphicsMailer : public MailInset {
125 InsetGraphicsMailer(InsetGraphics & inset);
127 virtual Inset & inset() const { return inset_; }
129 virtual std::string const & name() const { return name_; }
131 virtual std::string const inset2string(Buffer const &) const;
133 static void string2params(std::string const & data,
134 Buffer const & buffer,
135 InsetGraphicsParams &);
137 static std::string const params2string(InsetGraphicsParams const &,
141 static std::string const name_;
143 InsetGraphics & inset_;