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 "insets/inset.h"
23 #include "insets/insetgraphicsParams.h"
24 #include "graphics/GraphicsCacheItem.h"
25 #include <boost/smart_ptr.hpp>
27 #include "LaTeXFeatures.h"
29 // We need a signal here to hide an active dialog when we are deleted.
30 #include "sigc++/signal_system.h"
36 class InsetGraphics : public Inset, public SigC::Object {
41 InsetGraphics(InsetGraphics const &, bool same_id = false);
45 int ascent(BufferView *, LyXFont const &) const;
47 int descent(BufferView *, LyXFont const &) const;
49 int width(BufferView *, LyXFont const &) const;
51 bool display() const { return true; }
53 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
55 void edit(BufferView *, int, int, unsigned int);
57 void edit(BufferView * bv, bool front = true);
59 EDITABLE editable() const;
61 void write(Buffer const *, std::ostream &) const;
63 void read(Buffer const *, LyXLex & lex);
65 /** returns the number of rows (\n's) of generated tex code.
66 #fragile == true# means, that the inset should take care about
67 fragile commands by adding a #\protect# before.
69 int latex(Buffer const *, std::ostream &,
70 bool fragile, bool free_spc) const;
72 int ascii(Buffer const *, std::ostream &, int linelen) const;
74 int linuxdoc(Buffer const *, std::ostream &) const;
76 int docbook(Buffer const *, std::ostream &) const;
78 /** Tell LyX what the latex features you need i.e. what latex packages
79 you need to be included.
81 void validate(LaTeXFeatures & features) const;
83 /// returns LyX code associated with the inset. Used for TOC, ...)
84 Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
87 virtual Inset * clone(Buffer const &, bool same_id = false) const;
89 /** Set the inset parameters, used by the GUIndependent dialog.
90 Return true of new params are different from what was so far.
92 bool setParams(InsetGraphicsParams const & params);
94 /// Get the inset parameters, used by the GUIndependent dialog.
95 InsetGraphicsParams getParams() const;
97 /** This signal is connected by our dialog and called when the inset
100 SigC::Signal0<void> hideDialog;
103 /// Read the inset native format
104 void readInsetGraphics(Buffer const * buf, LyXLex & lex);
105 /// Read the FigInset file format
106 void readFigInset(Buffer const * buf, LyXLex & lex);
108 /// Update the inset after parameter change.
109 void updateInset() const;
110 /// Get the status message, depends on the image loading status.
111 string const statusMessage() const;
112 /// Create the options for the latex command.
113 string const createLatexOptions() const;
114 /// Convert the file if needed, and return the location of the file.
115 string const prepareFile(Buffer const * buf) const;
116 /// The graphics cache handle.
117 mutable boost::shared_ptr<GraphicsCacheItem> cacheHandle;
118 /// is the pixmap initialized?
119 mutable bool imageLoaded;
121 InsetGraphicsParams params;
122 /// holds the entity name that defines the graphics location (SGML).
123 string const graphic_label;