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>
29 #include <memory> // auto_ptr
35 class InsetGraphics : public Inset, public boost::signals::trackable {
40 InsetGraphics(InsetGraphics const &, string const & filepath,
41 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 void draw(BufferView *, LyXFont const &, int, float &, bool) const;
53 void edit(BufferView *, int, int, mouse_button::state);
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 &, bool mixcont) 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,
91 string const & filepath);
93 /// Get the inset parameters, used by the GUIndependent dialog.
94 InsetGraphicsParams const & params() const;
96 /** This signal is connected by our dialog and called when the inset
99 boost::signal0<void> hideDialog;
102 /// Is the image ready to draw, or should we display a message instead?
103 bool imageIsDrawable() const;
105 /** This method is connected to cache_->statusChanged, so we are
106 informed when the image has been loaded.
108 void statusChanged();
110 /// Read the inset native format
111 void readInsetGraphics(LyXLex & lex);
112 /// Read the FigInset file format
113 void readFigInset(LyXLex & lex);
115 /// Get the status message, depends on the image loading status.
116 string const statusMessage() const;
117 /// Create the options for the latex command.
118 string const createLatexOptions() const;
119 /// Convert the file if needed, and return the location of the file.
120 string const prepareFile(Buffer const * buf) const;
123 InsetGraphicsParams params_;
125 /// holds the entity name that defines the graphics location (SGML).
126 string const graphic_label;
128 /// The cached variables
131 /** Can change the contents of the cache, but not the pointer.
132 * Use std::auto_ptr not boost::scoped_ptr so we do not have to define
135 std::auto_ptr<Cache> const cache_;