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"
25 // We need a signal here to hide an active dialog when we are deleted.
26 #include <boost/signals/signal0.hpp>
27 #include <boost/signals/trackable.hpp>
28 #include <boost/scoped_ptr.hpp>
34 class InsetGraphics : public Inset, public boost::signals::trackable {
39 InsetGraphics(InsetGraphics const &, string const & filepath,
40 bool same_id = false);
44 int ascent(BufferView *, LyXFont const &) const;
46 int descent(BufferView *, LyXFont const &) const;
48 int width(BufferView *, LyXFont const &) const;
50 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
52 void edit(BufferView *, int, int, mouse_button::state);
54 void edit(BufferView * bv, bool front = true);
56 EDITABLE editable() const;
58 void write(Buffer const *, std::ostream &) const;
60 void read(Buffer const *, LyXLex & lex);
62 /** returns the number of rows (\n's) of generated tex code.
63 #fragile == true# means, that the inset should take care about
64 fragile commands by adding a #\protect# before.
66 int latex(Buffer const *, std::ostream &,
67 bool fragile, bool free_spc) const;
69 int ascii(Buffer const *, std::ostream &, int linelen) const;
71 int linuxdoc(Buffer const *, std::ostream &) const;
73 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
75 /** Tell LyX what the latex features you need i.e. what latex packages
76 you need to be included.
78 void validate(LaTeXFeatures & features) const;
80 /// returns LyX code associated with the inset. Used for TOC, ...)
81 Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
84 virtual Inset * clone(Buffer const &, bool same_id = false) const;
86 /** Set the inset parameters, used by the GUIndependent dialog.
87 Return true of new params are different from what was so far.
89 bool setParams(InsetGraphicsParams const & params,
90 string const & filepath);
92 /// Get the inset parameters, used by the GUIndependent dialog.
93 InsetGraphicsParams const & params() const;
95 /** This signal is connected by our dialog and called when the inset
98 boost::signal0<void> hideDialog;
101 /// Is the image ready to draw, or should we display a message instead?
102 bool imageIsDrawable() const;
104 /** This method is connected to cache_->statusChanged, so we are
105 informed when the image has been loaded.
107 void statusChanged();
109 /// Read the inset native format
110 void readInsetGraphics(LyXLex & lex);
112 /// Get the status message, depends on the image loading status.
113 string const statusMessage() const;
114 /// Create the options for the latex command.
115 string const createLatexOptions() const;
116 /// Convert the file if needed, and return the location of the file.
117 string const prepareFile(Buffer const * buf) const;
120 InsetGraphicsParams params_;
122 /// holds the entity name that defines the graphics location (SGML).
123 string const graphic_label;
125 /// The cached variables
128 /// The pointer never changes although *cache_'s contents may.
129 boost::scoped_ptr<Cache> const cache_;