]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
This makes fluctuation of inset hopefully better (#147).
[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  * ====================================================== */
11
12 #ifndef INSET_GRAPHICS_H
13 #define INSET_GRAPHICS_H
14
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif 
19
20 #include "insets/inset.h"
21 #include "insets/insetgraphicsParams.h"
22 #include "graphics/GraphicsCacheItem.h"
23 #include <boost/smart_ptr.hpp>
24
25 #include "LaTeXFeatures.h"
26
27 // We need a signal here to hide an active dialog when we are deleted.
28 #include "sigc++/signal_system.h"
29
30 class Dialogs;
31 class LyXImage;
32
33 ///
34 class InsetGraphics : public Inset, public SigC::Object {
35 public:
36         ///
37         InsetGraphics();
38         ///
39         InsetGraphics(InsetGraphics const &, bool same_id = false);
40         ///
41         ~InsetGraphics();
42         ///
43         int ascent(BufferView *, LyXFont const &) const;
44         ///
45         int descent(BufferView *, LyXFont const &) const;
46         ///
47         int width(BufferView *, LyXFont const &) const;
48         ///
49         bool display() const { return true; }
50         ///
51         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
52         ///
53         void edit(BufferView *, int, int, unsigned int);
54         ///
55         void edit(BufferView * bv, bool front = true);
56         ///
57         EDITABLE editable() const;
58         ///
59         void write(Buffer const *, std::ostream &) const;
60         ///
61         void read(Buffer const *, LyXLex & lex);
62
63         /** returns the number of rows (\n's) of generated tex code.
64          #fragile == true# means, that the inset should take care about
65          fragile commands by adding a #\protect# before.
66          */
67         int latex(Buffer const *, std::ostream &,
68                   bool fragile, bool free_spc) const;
69         ///
70         int ascii(Buffer const *, std::ostream &, int linelen) const;
71         ///
72         int linuxdoc(Buffer const *, std::ostream &) const;
73         ///
74         int docbook(Buffer const *, std::ostream &) const;
75
76         /** Tell LyX what the latex features you need i.e. what latex packages
77             you need to be included.
78          */
79         void validate(LaTeXFeatures & features) const;
80
81         /// returns LyX code associated with the inset. Used for TOC, ...)
82         Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
83
84         ///
85         virtual Inset * clone(Buffer const &, bool same_id = false) const;
86
87         /** Set the inset parameters, used by the GUIndependent dialog.
88             Return true of new params are different from what was so far.
89         */
90         bool setParams(InsetGraphicsParams const & params);
91
92         /// Get the inset parameters, used by the GUIndependent dialog.
93         InsetGraphicsParams getParams() const;
94
95         /** This signal is connected by our dialog and called when the inset
96             is deleted.
97         */
98         SigC::Signal0<void> hideDialog;
99
100 private:
101         /// Read the inset native format
102         void readInsetGraphics(Buffer const * buf, LyXLex & lex);
103         /// Read the FigInset file format
104         void readFigInset(Buffer const * buf, LyXLex & lex);
105         
106         /// Update the inset after parameter change.
107         void updateInset() const;
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         /// The graphics cache handle.
115         mutable boost::shared_ptr<GraphicsCacheItem> cacheHandle;
116         /// is the pixmap initialized?
117         mutable bool imageLoaded;
118         ///
119         InsetGraphicsParams params;
120 };
121
122 #endif