]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
ws cleanup
[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 "graphics/GraphicsTypes.h"
23 #include "insets/inset.h"
24 #include "insets/insetgraphicsParams.h"
25 // We need a signal here to hide an active dialog when we are deleted.
26 #include "sigc++/signal_system.h"
27
28 class Dialogs;
29 class LaTeXFeatures;
30
31 ///
32 class InsetGraphics : public Inset, public SigC::Object {
33 public:
34         ///
35         InsetGraphics();
36         ///
37         InsetGraphics(InsetGraphics const &, bool same_id = false);
38         ///
39         ~InsetGraphics();
40         ///
41         int ascent(BufferView *, LyXFont const &) const;
42         ///
43         int descent(BufferView *, LyXFont const &) const;
44         ///
45         int width(BufferView *, LyXFont const &) const;
46         ///
47         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
48         ///
49         void edit(BufferView *, int, int, unsigned int);
50         ///
51         void edit(BufferView * bv, bool front = true);
52         ///
53         EDITABLE editable() const;
54         ///
55         void write(Buffer const *, std::ostream &) const;
56         ///
57         void read(Buffer const *, LyXLex & lex);
58
59         /** returns the number of rows (\n's) of generated tex code.
60          #fragile == true# means, that the inset should take care about
61          fragile commands by adding a #\protect# before.
62          */
63         int latex(Buffer const *, std::ostream &,
64                   bool fragile, bool free_spc) const;
65         ///
66         int ascii(Buffer const *, std::ostream &, int linelen) const;
67         ///
68         int linuxdoc(Buffer const *, std::ostream &) const;
69         ///
70         int docbook(Buffer const *, std::ostream &) const;
71
72         /** Tell LyX what the latex features you need i.e. what latex packages
73             you need to be included.
74          */
75         void validate(LaTeXFeatures & features) const;
76
77         /// returns LyX code associated with the inset. Used for TOC, ...)
78         Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
79
80         ///
81         virtual Inset * clone(Buffer const &, bool same_id = false) const;
82
83         /** Set the inset parameters, used by the GUIndependent dialog.
84             Return true of new params are different from what was so far.
85         */
86         bool setParams(InsetGraphicsParams const & params);
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         SigC::Signal0<void> hideDialog;
95
96 private:
97         /// Set the cached variables
98         void setCache() const;
99         /// Is the image ready to draw, or should we display a message instead?
100         bool drawImage() const;
101
102         /// Read the inset native format
103         void readInsetGraphics(Buffer const * buf, LyXLex & lex);
104         /// Read the FigInset file format
105         void readFigInset(Buffer const * buf, LyXLex & lex);
106
107         /// Update the inset after parameter change.
108         void updateInset() const;
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         mutable grfx::ImageStatus cached_status_;
124         ///
125         mutable grfx::ImagePtr cached_image_;
126         ///
127         mutable bool cache_filled_;
128         ///
129         mutable int old_asc;
130 };
131
132 #endif