]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
aa9dc9d6cf19fd46101fbe3ea3a0f11e6e8b765a
[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();
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         bool display() const { return true; }
48         ///
49         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
50         ///
51         void edit(BufferView *, int, int, unsigned int);
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 getParams() 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         /// Update the inset after parameter change.
98         void updateInset() const;
99         /// Get the status message, depends on the image loading status.
100         string const statusMessage() const;
101         /// Create the options for the latex command.
102         string const createLatexOptions() const;
103         /// Convert the file if needed, and return the location of the file.
104         string const prepareFile(Buffer const * buf) const;
105         /// The graphics cache handle.
106         mutable boost::shared_ptr<GraphicsCacheItem> cacheHandle;
107         /// is the pixmap initialized?
108         mutable bool imageLoaded;
109         ///
110         InsetGraphicsParams params;
111 };
112
113 #endif