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