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
18 #include "insets/inset.h"
19 #include "insets/insetgraphicsParams.h"
21 #include <boost/signals/trackable.hpp>
22 #include <boost/scoped_ptr.hpp>
28 class InsetGraphics : public Inset, public boost::signals::trackable {
33 InsetGraphics(InsetGraphics const &, string const & filepath,
34 bool same_id = false);
38 virtual dispatch_result localDispatch(FuncRequest const & cmd);
40 int ascent(BufferView *, LyXFont const &) const;
42 int descent(BufferView *, LyXFont const &) const;
44 int width(BufferView *, LyXFont const &) const;
46 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
48 void edit(BufferView *, int, int, mouse_button::state);
50 void edit(BufferView * bv, bool front = true);
52 EDITABLE editable() const;
54 void write(Buffer const *, std::ostream &) const;
56 void read(Buffer const *, LyXLex & lex);
58 /** returns the number of rows (\n's) of generated tex code.
59 #fragile == true# means, that the inset should take care about
60 fragile commands by adding a #\protect# before.
62 int latex(Buffer const *, std::ostream &,
63 bool fragile, bool free_spc) const;
65 int ascii(Buffer const *, std::ostream &, int linelen) const;
67 int linuxdoc(Buffer const *, std::ostream &) const;
69 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
71 /** Tell LyX what the latex features you need i.e. what latex packages
72 you need to be included.
74 void validate(LaTeXFeatures & features) const;
76 /// returns LyX code associated with the inset. Used for TOC, ...)
77 Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
80 virtual Inset * clone(Buffer const &, bool same_id = false) const;
82 /** Set the inset parameters, used by the GUIndependent dialog.
83 Return true of new params are different from what was so far.
85 bool setParams(InsetGraphicsParams const & params,
86 string const & filepath);
88 /// Get the inset parameters, used by the GUIndependent dialog.
89 InsetGraphicsParams const & params() const;
92 /// Returns the cached BufferView.
93 BufferView * view() const;
96 friend class InsetGraphicsMailer;
98 /// Is the image ready to draw, or should we display a message instead?
99 bool imageIsDrawable() const;
101 /** This method is connected to cache_->statusChanged, so we are
102 informed when the image has been loaded.
104 void statusChanged();
106 /// Read the inset native format
107 void readInsetGraphics(LyXLex & lex);
109 /// Get the status message, depends on the image loading status.
110 string const statusMessage() const;
111 /// Create the options for the latex command.
112 string const createLatexOptions() const;
113 /// Convert the file if needed, and return the location of the file.
114 string const prepareFile(Buffer const * buf) const;
117 InsetGraphicsParams params_;
119 /// holds the entity name that defines the graphics location (SGML).
120 string const graphic_label;
122 /// The cached variables
125 /// The pointer never changes although *cache_'s contents may.
126 boost::scoped_ptr<Cache> const cache_;
130 #include "mailinset.h"
132 class InsetGraphicsMailer : public MailInset {
135 InsetGraphicsMailer(InsetGraphics & inset);
137 virtual InsetBase & inset() const { return inset_; }
139 virtual string const & name() const { return name_; }
141 virtual string const inset2string() const;
143 static void string2params(string const &, InsetGraphicsParams &);
145 static string const params2string(InsetGraphicsParams const &);
148 static string const name_;
150 InsetGraphics & inset_;