]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
*** empty log message ***
[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 // We need a signal here to hide an active dialog when we are deleted.
22 #include <boost/signals/signal0.hpp>
23 #include <boost/signals/trackable.hpp>
24 #include <boost/scoped_ptr.hpp>
25
26 class Dialogs;
27 class LaTeXFeatures;
28
29 ///
30 class InsetGraphics : public Inset, public boost::signals::trackable {
31 public:
32         ///
33         InsetGraphics();
34         ///
35         InsetGraphics(InsetGraphics const &, string const & filepath,
36                       bool same_id = false);
37         ///
38         ~InsetGraphics();
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         /** This signal is connected by our dialog and called when the inset
92             is deleted.
93         */
94         boost::signal0<void> hideDialog;
95
96 private:
97         /// Is the image ready to draw, or should we display a message instead?
98         bool imageIsDrawable() const;
99
100         /** This method is connected to cache_->statusChanged, so we are
101             informed when the image has been loaded.
102          */
103         void statusChanged();
104
105         /// Read the inset native format
106         void readInsetGraphics(LyXLex & lex);
107
108         /// Get the status message, depends on the image loading status.
109         string const statusMessage() const;
110         /// Create the options for the latex command.
111         string const createLatexOptions() const;
112         /// Convert the file if needed, and return the location of the file.
113         string const prepareFile(Buffer const * buf) const;
114
115         ///
116         InsetGraphicsParams params_;
117
118         /// holds the entity name that defines the graphics location (SGML).
119         string const graphic_label;
120
121         /// The cached variables
122         class Cache;
123         friend class Cache;
124         /// The pointer never changes although *cache_'s contents may.
125         boost::scoped_ptr<Cache> const cache_;
126 };
127
128 #endif