]> git.lyx.org Git - lyx.git/blob - src/insets/insetgraphics.h
redraw fix 1.
[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 "insets/insetgraphicsParams.h"
24
25 // We need a signal here to hide an active dialog when we are deleted.
26 #include <boost/signals/signal0.hpp>
27 #include <boost/signals/trackable.hpp>
28 #include <boost/scoped_ptr.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         /// Is the image ready to draw, or should we display a message instead?
102         bool imageIsDrawable() const;
103
104         /** This method is connected to cache_->statusChanged, so we are
105             informed when the image has been loaded.
106          */
107         void statusChanged();
108
109         /// Read the inset native format
110         void readInsetGraphics(LyXLex & lex);
111         /// Read the FigInset file format
112         void readFigInset(LyXLex & lex);
113
114         /// Get the status message, depends on the image loading status.
115         string const statusMessage() const;
116         /// Create the options for the latex command.
117         string const createLatexOptions() const;
118         /// Convert the file if needed, and return the location of the file.
119         string const prepareFile(Buffer const * buf) const;
120
121         ///
122         InsetGraphicsParams params_;
123
124         /// holds the entity name that defines the graphics location (SGML).
125         string const graphic_label;
126
127         /// The cached variables
128         class Cache;
129         friend class Cache;
130         /// The pointer never changes although *cache_'s contents may.
131         boost::scoped_ptr<Cache> const cache_;
132 };
133
134 #endif