]> git.lyx.org Git - lyx.git/blob - src/insets/InsetGraphics.h
Remove TextClassPtr without losing the type safety it provided.
[lyx.git] / src / insets / InsetGraphics.h
1 // -*- C++ -*-
2 /**
3  * \file InsetGraphics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_GRAPHICS_H
14 #define INSET_GRAPHICS_H
15
16 #include "Inset.h"
17 #include "InsetGraphicsParams.h"
18 #include "MailInset.h"
19
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signals/trackable.hpp>
22
23
24 namespace lyx {
25
26 class RenderGraphic;
27 class LaTeXFeatures;
28
29 ///
30 class InsetGraphics : public Inset, public boost::signals::trackable {
31 public:
32         ///
33         InsetGraphics();
34         ///
35         ~InsetGraphics();
36         ///
37         void metrics(MetricsInfo &, Dimension &) const;
38         ///
39         EDITABLE editable() const;
40         ///
41         void write(std::ostream &) const;
42         ///
43         void read(Lexer & lex);
44
45         /** returns the number of rows (\n's) of generated tex code.
46          #fragile == true# means, that the inset should take care about
47          fragile commands by adding a #\protect# before.
48          */
49         int latex(odocstream &, OutputParams const &) const;
50         ///
51         int plaintext(odocstream &, OutputParams const &) const;
52         ///
53         int docbook(odocstream &, OutputParams const &) const;
54
55         /** Tell LyX what the latex features you need i.e. what latex packages
56             you need to be included.
57          */
58         void validate(LaTeXFeatures & features) const;
59
60         /// returns LyX code associated with the inset. Used for TOC, ...)
61         InsetCode lyxCode() const { return GRAPHICS_CODE; }
62
63         /** Set the inset parameters, used by the GUIndependent dialog.
64             Return true of new params are different from what was so far.
65         */
66         bool setParams(InsetGraphicsParams const & params);
67
68         /// Get the inset parameters, used by the GUIndependent dialog.
69         InsetGraphicsParams const & params() const;
70         ///
71         void draw(PainterInfo & pi, int x, int y) const;
72         ///
73         void edit(Cursor & cur, bool front, EntryDirection entry_from);
74         ///
75         void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
76         ///
77         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
78         /// all graphics can be embedded
79         void registerEmbeddedFiles(EmbeddedFileList &) const;
80         ///
81         void updateEmbeddedFile(EmbeddedFile const &);
82         /// Force inset into LTR environment if surroundings are RTL?
83         virtual bool forceLTR() const { return true; }
84 protected:
85         InsetGraphics(InsetGraphics const &);
86         ///
87         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
88 private:
89         friend class InsetGraphicsMailer;
90
91         virtual Inset * clone() const;
92
93         /// Read the inset native format
94         void readInsetGraphics(Lexer & lex, std::string const & bufpath);
95
96         /// Get the status message, depends on the image loading status.
97         std::string const statusMessage() const;
98         /// Create the options for the latex command.
99         std::string const createLatexOptions() const;
100         /// Create length values for docbook export.
101         docstring const toDocbookLength(Length const & len) const;
102         /// Create the atributes for docbook export.
103         docstring const createDocBookAttributes() const;
104         /// Convert the file if needed, and return the location of the file.
105         std::string prepareFile(OutputParams const &) const;
106
107         ///
108         InsetGraphicsParams params_;
109
110         /// holds the entity name that defines the graphics location (SGML).
111         docstring const graphic_label;
112
113         /// The thing that actually draws the image on LyX's screen.
114         boost::scoped_ptr<RenderGraphic> const graphic_;
115 };
116
117
118 class InsetGraphicsMailer : public MailInset {
119 public:
120         ///
121         InsetGraphicsMailer(InsetGraphics & inset);
122         ///
123         virtual Inset & inset() const { return inset_; }
124         ///
125         virtual std::string const & name() const { return name_; }
126         ///
127         virtual std::string const inset2string(Buffer const &) const;
128         ///
129         static void string2params(std::string const & data,
130                                   Buffer const & buffer,
131                                   InsetGraphicsParams &);
132         ///
133         static std::string const params2string(InsetGraphicsParams const &,
134                                           Buffer const &);
135 private:
136         ///
137         static std::string const name_;
138         ///
139         InsetGraphics & inset_;
140 };
141
142
143 } // namespace lyx
144
145 #endif