2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 the LyX Team.
10 * ====================================================== */
12 #ifndef INSET_GRAPHICS_H
13 #define INSET_GRAPHICS_H
20 #include "insets/inset.h"
21 #include "insets/insetgraphicsParams.h"
22 #include "graphics/GraphicsCacheItem.h"
23 #include <boost/smart_ptr.hpp>
25 #include "LaTeXFeatures.h"
27 // We need a signal here to hide an active dialog when we are deleted.
28 #include "sigc++/signal_system.h"
34 class InsetGraphics : public Inset, public SigC::Object {
39 InsetGraphics(InsetGraphics const &, bool same_id = false);
43 int ascent(BufferView *, LyXFont const &) const;
45 int descent(BufferView *, LyXFont const &) const;
47 int width(BufferView *, LyXFont const &) const;
49 bool display() const { return true; }
51 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
53 void edit(BufferView *, int, int, unsigned int);
55 void edit(BufferView * bv, bool front = true);
57 EDITABLE editable() const;
59 void write(Buffer const *, std::ostream &) const;
61 void read(Buffer const *, LyXLex & lex);
63 /** returns the number of rows (\n's) of generated tex code.
64 #fragile == true# means, that the inset should take care about
65 fragile commands by adding a #\protect# before.
67 int latex(Buffer const *, std::ostream &,
68 bool fragile, bool free_spc) const;
70 int ascii(Buffer const *, std::ostream &, int linelen) const;
72 int linuxdoc(Buffer const *, std::ostream &) const;
74 int docbook(Buffer const *, std::ostream &) const;
76 /** Tell LyX what the latex features you need i.e. what latex packages
77 you need to be included.
79 void validate(LaTeXFeatures & features) const;
81 /// returns LyX code associated with the inset. Used for TOC, ...)
82 Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
85 virtual Inset * clone(Buffer const &, bool same_id = false) const;
87 /** Set the inset parameters, used by the GUIndependent dialog.
88 Return true of new params are different from what was so far.
90 bool setParams(InsetGraphicsParams const & params);
92 /// Get the inset parameters, used by the GUIndependent dialog.
93 InsetGraphicsParams getParams() const;
95 /** This signal is connected by our dialog and called when the inset
98 SigC::Signal0<void> hideDialog;
101 /// Read the inset native format
102 void readInsetGraphics(Buffer const * buf, LyXLex & lex);
103 /// Read the FigInset file format
104 void readFigInset(Buffer const * buf, LyXLex & lex);
106 /// Update the inset after parameter change.
107 void updateInset() const;
108 /// Get the status message, depends on the image loading status.
109 string const statusMessage() const;
110 /// Create the options for the latex command.
111 string const createLatexOptions() const;
112 /// Convert the file if needed, and return the location of the file.
113 string const prepareFile(Buffer const * buf) const;
114 /// The graphics cache handle.
115 mutable boost::shared_ptr<GraphicsCacheItem> cacheHandle;
116 /// is the pixmap initialized?
117 mutable bool imageLoaded;
119 InsetGraphicsParams params;