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