]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
62a6216f86f2be3cb73cb2815af350b84023ffe9
[lyx.git] / src / insets / insetgraphics.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 the LyX Team.
9  *
10  * \author Baruch Even
11  * \author Herbert Voss <voss@lyx.org>
12  * ====================================================== */
13
14 #ifndef INSET_GRAPHICS_H
15 #define INSET_GRAPHICS_H
16
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "insets/inset.h"
23 #include "insets/insetgraphicsParams.h"
24
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
29 #include <memory> // auto_ptr
30
31 class Dialogs;
32 class LaTeXFeatures;
33
34 ///
35 class InsetGraphics : public Inset, public boost::signals::trackable {
36 public:
37         ///
38         InsetGraphics();
39         ///
40         InsetGraphics(InsetGraphics const &, string const & filepath,
41                       bool same_id = false);
42         ///
43         ~InsetGraphics();
44         ///
45         int ascent(BufferView *, LyXFont const &) const;
46         ///
47         int descent(BufferView *, LyXFont const &) const;
48         ///
49         int width(BufferView *, LyXFont const &) const;
50         ///
51         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
52         ///
53         void edit(BufferView *, int, int, mouse_button::state);
54         ///
55         void edit(BufferView * bv, bool front = true);
56         ///
57         EDITABLE editable() const;
58         ///
59         void write(Buffer const *, std::ostream &) const;
60         ///
61         void read(Buffer const *, LyXLex & lex);
62
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.
66          */
67         int latex(Buffer const *, std::ostream &,
68                   bool fragile, bool free_spc) const;
69         ///
70         int ascii(Buffer const *, std::ostream &, int linelen) const;
71         ///
72         int linuxdoc(Buffer const *, std::ostream &) const;
73         ///
74         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
75
76         /** Tell LyX what the latex features you need i.e. what latex packages
77             you need to be included.
78          */
79         void validate(LaTeXFeatures & features) const;
80
81         /// returns LyX code associated with the inset. Used for TOC, ...)
82         Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
83
84         ///
85         virtual Inset * clone(Buffer const &, bool same_id = false) const;
86
87         /** Set the inset parameters, used by the GUIndependent dialog.
88             Return true of new params are different from what was so far.
89         */
90         bool setParams(InsetGraphicsParams const & params,
91                        string const & filepath);
92
93         /// Get the inset parameters, used by the GUIndependent dialog.
94         InsetGraphicsParams const & params() const;
95
96         /** This signal is connected by our dialog and called when the inset
97             is deleted.
98         */
99         boost::signal0<void> hideDialog;
100
101 private:
102         /// Is the image ready to draw, or should we display a message instead?
103         bool imageIsDrawable() const;
104
105         /** This method is connected to cache_->statusChanged, so we are
106             informed when the image has been loaded.
107          */
108         void statusChanged();
109
110         /// Read the inset native format
111         void readInsetGraphics(LyXLex & lex);
112         /// Read the FigInset file format
113         void readFigInset(LyXLex & lex);
114
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;
121
122         ///
123         InsetGraphicsParams params_;
124
125         /// holds the entity name that defines the graphics location (SGML).
126         string const graphic_label;
127
128         /// The cached variables
129         class Cache;
130         friend class Cache;
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
133          *  Cache in advance.
134          */
135         std::auto_ptr<Cache> const cache_;
136 };
137
138 #endif