]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
7aa5967d37220aac40c167ea10ed71527049629f
[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 "graphics/GraphicsTypes.h"
24 #include "insets/insetgraphicsParams.h"
25
26 // We need a signal here to hide an active dialog when we are deleted.
27 #include <boost/signals/signal0.hpp>
28 #include <boost/signals/trackable.hpp>
29
30 class Dialogs;
31 class LaTeXFeatures;
32
33 ///
34 class InsetGraphics : public Inset, public boost::signals::trackable {
35 public:
36         ///
37         InsetGraphics();
38         ///
39         InsetGraphics(InsetGraphics const &, string const & filepath,
40                       bool same_id = false);
41         ///
42         ~InsetGraphics();
43         ///
44         int ascent(BufferView *, LyXFont const &) const;
45         ///
46         int descent(BufferView *, LyXFont const &) const;
47         ///
48         int width(BufferView *, LyXFont const &) const;
49         ///
50         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
51         ///
52         void edit(BufferView *, int, int, mouse_button::state);
53         ///
54         void edit(BufferView * bv, bool front = true);
55         ///
56         EDITABLE editable() const;
57         ///
58         void write(Buffer const *, std::ostream &) const;
59         ///
60         void read(Buffer const *, LyXLex & lex);
61
62         /** returns the number of rows (\n's) of generated tex code.
63          #fragile == true# means, that the inset should take care about
64          fragile commands by adding a #\protect# before.
65          */
66         int latex(Buffer const *, std::ostream &,
67                   bool fragile, bool free_spc) const;
68         ///
69         int ascii(Buffer const *, std::ostream &, int linelen) const;
70         ///
71         int linuxdoc(Buffer const *, std::ostream &) const;
72         ///
73         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
74
75         /** Tell LyX what the latex features you need i.e. what latex packages
76             you need to be included.
77          */
78         void validate(LaTeXFeatures & features) const;
79
80         /// returns LyX code associated with the inset. Used for TOC, ...)
81         Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
82
83         ///
84         virtual Inset * clone(Buffer const &, bool same_id = false) const;
85
86         /** Set the inset parameters, used by the GUIndependent dialog.
87             Return true of new params are different from what was so far.
88         */
89         bool setParams(InsetGraphicsParams const & params,
90                        string const & filepath);
91
92         /// Get the inset parameters, used by the GUIndependent dialog.
93         InsetGraphicsParams const & params() const;
94
95         /** This signal is connected by our dialog and called when the inset
96             is deleted.
97         */
98         boost::signal0<void> hideDialog;
99
100 private:
101         /// Set the cached variables
102         void setCache() const;
103         /// Is the image ready to draw, or should we display a message instead?
104         bool drawImage() const;
105
106         /// Read the inset native format
107         void readInsetGraphics(LyXLex & lex);
108         /// Read the FigInset file format
109         void readFigInset(LyXLex & lex);
110
111         /// Update the inset after parameter change.
112         void updateInset(string const & filepath) const;
113         /// Get the status message, depends on the image loading status.
114         string const statusMessage() const;
115         /// Create the options for the latex command.
116         string const createLatexOptions() const;
117         /// Convert the file if needed, and return the location of the file.
118         string const prepareFile(Buffer const * buf) const;
119
120         ///
121         InsetGraphicsParams params_;
122
123         /// holds the entity name that defines the graphics location (SGML).
124         string const graphic_label;
125
126         /// The cached variables
127         mutable grfx::ImageStatus cached_status_;
128         ///
129         mutable grfx::ImagePtr cached_image_;
130         ///
131         mutable bool cache_filled_;
132         ///
133         mutable int old_asc;
134 };
135
136 #endif