]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
edit->LFUN_INSET_EDIT + CHangeLog + working URL insets.
[lyx.git] / src / insets / insetgraphics.h
1 // -*- C++ -*-
2 /**
3  * \file insetgraphics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  * \author Herbert Voss
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #ifndef INSET_GRAPHICS_H
14 #define INSET_GRAPHICS_H
15
16 #include "insets/inset.h"
17 #include "insets/insetgraphicsParams.h"
18
19 #include <boost/signals/trackable.hpp>
20 #include <boost/scoped_ptr.hpp>
21
22 class Dialogs;
23 class LaTeXFeatures;
24
25 ///
26 class InsetGraphics : public Inset, public boost::signals::trackable {
27 public:
28         ///
29         InsetGraphics();
30         ///
31         InsetGraphics(InsetGraphics const &, string const & filepath,
32                       bool same_id = false);
33         ///
34         ~InsetGraphics();
35         ///
36         virtual dispatch_result localDispatch(FuncRequest const & cmd);
37         ///
38         int ascent(BufferView *, LyXFont const &) const;
39         ///
40         int descent(BufferView *, LyXFont const &) const;
41         ///
42         int width(BufferView *, LyXFont const &) const;
43         ///
44         void draw(BufferView *, LyXFont const &, int, float &) const;
45         ///
46         EDITABLE editable() const;
47         ///
48         void write(Buffer const *, std::ostream &) const;
49         ///
50         void read(Buffer const *, LyXLex & lex);
51
52         /** returns the number of rows (\n's) of generated tex code.
53          #fragile == true# means, that the inset should take care about
54          fragile commands by adding a #\protect# before.
55          */
56         int latex(Buffer const *, std::ostream &,
57                   bool fragile, bool free_spc) const;
58         ///
59         int ascii(Buffer const *, std::ostream &, int linelen) const;
60         ///
61         int linuxdoc(Buffer const *, std::ostream &) const;
62         ///
63         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
64
65         /** Tell LyX what the latex features you need i.e. what latex packages
66             you need to be included.
67          */
68         void validate(LaTeXFeatures & features) const;
69
70         /// returns LyX code associated with the inset. Used for TOC, ...)
71         Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
72
73         ///
74         virtual Inset * clone(Buffer const &, bool same_id = false) const;
75
76         /** Set the inset parameters, used by the GUIndependent dialog.
77             Return true of new params are different from what was so far.
78         */
79         bool setParams(InsetGraphicsParams const & params,
80                        string const & filepath);
81
82         /// Get the inset parameters, used by the GUIndependent dialog.
83         InsetGraphicsParams const & params() const;
84
85 private:
86         /// Returns the cached BufferView.
87         BufferView * view() const;
88
89         ///
90         friend class InsetGraphicsMailer;
91
92         /// Is the image ready to draw, or should we display a message instead?
93         bool imageIsDrawable() const;
94
95         /** This method is connected to cache_->statusChanged, so we are
96             informed when the image has been loaded.
97          */
98         void statusChanged();
99
100         /// Read the inset native format
101         void readInsetGraphics(LyXLex & lex);
102
103         /// Get the status message, depends on the image loading status.
104         string const statusMessage() const;
105         /// Create the options for the latex command.
106         string const createLatexOptions() const;
107         /// Convert the file if needed, and return the location of the file.
108         string const prepareFile(Buffer const * buf) const;
109
110         ///
111         InsetGraphicsParams params_;
112
113         /// holds the entity name that defines the graphics location (SGML).
114         string const graphic_label;
115
116         /// The cached variables
117         class Cache;
118         friend class Cache;
119         /// The pointer never changes although *cache_'s contents may.
120         boost::scoped_ptr<Cache> const cache_;
121 };
122
123
124 #include "mailinset.h"
125
126 class InsetGraphicsMailer : public MailInset {
127 public:
128         ///
129         InsetGraphicsMailer(InsetGraphics & inset);
130         ///
131         virtual InsetBase & inset() const { return inset_; }
132         ///
133         virtual string const & name() const { return name_; }
134         ///
135         virtual string const inset2string() const;
136         ///
137         static void string2params(string const &, InsetGraphicsParams &);
138         ///
139         static string const params2string(InsetGraphicsParams const &);
140 private:
141         ///
142         static string const name_;
143         ///
144         InsetGraphics & inset_;
145 };
146
147 #endif