2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 the LyX Team.
11 * \author Herbert Voss <voss@lyx.org>
12 * ====================================================== */
14 #ifndef INSET_GRAPHICS_H
15 #define INSET_GRAPHICS_H
22 #include "graphics/GraphicsTypes.h"
23 #include "insets/inset.h"
24 #include "insets/insetgraphicsParams.h"
25 // We need a signal here to hide an active dialog when we are deleted.
26 #include "sigc++/signal_system.h"
32 class InsetGraphics : public Inset, public SigC::Object {
37 InsetGraphics(InsetGraphics const &, string const & filepath,
38 bool same_id = false);
42 int ascent(BufferView *, LyXFont const &) const;
44 int descent(BufferView *, LyXFont const &) const;
46 int width(BufferView *, LyXFont const &) const;
48 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
50 void edit(BufferView *, int, int, unsigned int);
52 void edit(BufferView * bv, bool front = true);
54 EDITABLE editable() const;
56 void write(Buffer const *, std::ostream &) const;
58 void read(Buffer const *, LyXLex & lex);
60 /** returns the number of rows (\n's) of generated tex code.
61 #fragile == true# means, that the inset should take care about
62 fragile commands by adding a #\protect# before.
64 int latex(Buffer const *, std::ostream &,
65 bool fragile, bool free_spc) const;
67 int ascii(Buffer const *, std::ostream &, int linelen) const;
69 int linuxdoc(Buffer const *, std::ostream &) const;
71 int docbook(Buffer const *, std::ostream &) const;
73 /** Tell LyX what the latex features you need i.e. what latex packages
74 you need to be included.
76 void validate(LaTeXFeatures & features) const;
78 /// returns LyX code associated with the inset. Used for TOC, ...)
79 Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
82 virtual Inset * clone(Buffer const &, bool same_id = false) const;
84 /** Set the inset parameters, used by the GUIndependent dialog.
85 Return true of new params are different from what was so far.
87 bool setParams(InsetGraphicsParams const & params,
88 string const & filepath);
90 /// Get the inset parameters, used by the GUIndependent dialog.
91 InsetGraphicsParams const & params() const;
93 /** This signal is connected by our dialog and called when the inset
96 SigC::Signal0<void> hideDialog;
99 /// Set the cached variables
100 void setCache() const;
101 /// Is the image ready to draw, or should we display a message instead?
102 bool drawImage() const;
104 /// Read the inset native format
105 void readInsetGraphics(LyXLex & lex);
106 /// Read the FigInset file format
107 void readFigInset(LyXLex & lex);
109 /// Update the inset after parameter change.
110 void updateInset(string const & filepath) const;
111 /// Get the status message, depends on the image loading status.
112 string const statusMessage() const;
113 /// Create the options for the latex command.
114 string const createLatexOptions() const;
115 /// Convert the file if needed, and return the location of the file.
116 string const prepareFile(Buffer const * buf) const;
119 InsetGraphicsParams params_;
121 /// holds the entity name that defines the graphics location (SGML).
122 string const graphic_label;
124 /// The cached variables
125 mutable grfx::ImageStatus cached_status_;
127 mutable grfx::ImagePtr cached_image_;
129 mutable bool cache_filled_;