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 "graphics/GraphicsTypes.h"
24 #include "insets/insetgraphicsParams.h"
26 // We need a signal here to hide an active dialog when we are deleted.
27 #include <boost/signals/signal0.hpp>
28 #include <boost/signals/trackable.hpp>
30 #include <memory> // auto_ptr
36 class InsetGraphics : public Inset, public boost::signals::trackable {
41 InsetGraphics(InsetGraphics const &, string const & filepath,
42 bool same_id = false);
46 int ascent(BufferView *, LyXFont const &) const;
48 int descent(BufferView *, LyXFont const &) const;
50 int width(BufferView *, LyXFont const &) const;
52 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
54 void edit(BufferView *, int, int, mouse_button::state);
56 void edit(BufferView * bv, bool front = true);
58 EDITABLE editable() const;
60 void write(Buffer const *, std::ostream &) const;
62 void read(Buffer const *, LyXLex & lex);
64 /** returns the number of rows (\n's) of generated tex code.
65 #fragile == true# means, that the inset should take care about
66 fragile commands by adding a #\protect# before.
68 int latex(Buffer const *, std::ostream &,
69 bool fragile, bool free_spc) const;
71 int ascii(Buffer const *, std::ostream &, int linelen) const;
73 int linuxdoc(Buffer const *, std::ostream &) const;
75 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
77 /** Tell LyX what the latex features you need i.e. what latex packages
78 you need to be included.
80 void validate(LaTeXFeatures & features) const;
82 /// returns LyX code associated with the inset. Used for TOC, ...)
83 Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
86 virtual Inset * clone(Buffer const &, bool same_id = false) const;
88 /** Set the inset parameters, used by the GUIndependent dialog.
89 Return true of new params are different from what was so far.
91 bool setParams(InsetGraphicsParams const & params,
92 string const & filepath);
94 /// Get the inset parameters, used by the GUIndependent dialog.
95 InsetGraphicsParams const & params() const;
97 /** This signal is connected by our dialog and called when the inset
100 boost::signal0<void> hideDialog;
103 /// Is the image ready to draw, or should we display a message instead?
104 bool imageIsDrawable() const;
106 /** This method is connected to cache_->statusChanged, so we are
107 informed when the image has been loaded.
109 void statusChanged();
111 /// Read the inset native format
112 void readInsetGraphics(LyXLex & lex);
113 /// Read the FigInset file format
114 void readFigInset(LyXLex & lex);
116 /// Get the status message, depends on the image loading status.
117 string const statusMessage() const;
118 /// Create the options for the latex command.
119 string const createLatexOptions() const;
120 /// Convert the file if needed, and return the location of the file.
121 string const prepareFile(Buffer const * buf) const;
124 InsetGraphicsParams params_;
126 /// holds the entity name that defines the graphics location (SGML).
127 string const graphic_label;
129 /// The cached variables
132 /** Can change the contents of the cache, but not the pointer.
133 * Use std::auto_ptr not boost::scoped_ptr so we do not have to define
136 std::auto_ptr<Cache> const cache_;