]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
fix #4717
[lyx.git] / src / insets / InsetExternal.h
1 // -*- C++ -*-
2 /**
3  * \file InsetExternal.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup Nielsen
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSET_EXTERNAL_H
13 #define INSET_EXTERNAL_H
14
15 #include "Inset.h"
16 #include "ExternalTransforms.h"
17 #include "EmbeddedFiles.h"
18
19 #include "support/FileName.h"
20 #include "support/Translator.h"
21
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
24
25
26 /** No two InsetExternalParams variables can have the same temporary file.
27  *  This class has copy-semantics but the copy constructor
28  *  and assignment operator simply call the default constructor.
29  *  Use of this class enables us to use the compiler-generated
30  *  copy constructor and assignment operator for the
31  *  InsetExternalParams class.
32  */
33 namespace lyx {
34
35 namespace external {
36
37 class TempName {
38 public:
39         TempName();
40         TempName(TempName const &);
41         ~TempName();
42         TempName & operator=(TempName const &);
43         support::FileName const & operator()() const { return tempname_; }
44 private:
45         support::FileName tempname_;
46 };
47
48 /// How is the image to be displayed on the LyX screen?
49 enum DisplayType {
50         DefaultDisplay,
51         MonochromeDisplay,
52         GrayscaleDisplay,
53         ColorDisplay,
54         PreviewDisplay,
55         NoDisplay
56 };
57
58
59 /// The translator between the Display enum and corresponding lyx string.
60 Translator<DisplayType, std::string> const & displayTranslator();
61
62 } // namespace external
63
64
65 /// hold parameters settable from the GUI
66 class InsetExternalParams {
67 public:
68         InsetExternalParams();
69
70         void write(Buffer const &, std::ostream &) const;
71         bool read(Buffer const &, Lexer &);
72
73         /// The name of the tempfile used for manipulations.
74         support::FileName const & tempname() const { return tempname_(); }
75
76         /// The template currently in use.
77         void settemplate(std::string const &);
78         std::string const & templatename() const { return templatename_; }
79
80         /// The external file.
81         EmbeddedFile filename;
82         /// How the inset is to be displayed by LyX.
83         external::DisplayType display;
84         /// The scale of the displayed graphic (if shown).
85         unsigned int lyxscale;
86
87         external::ClipData     clipdata;
88         external::ExtraData    extradata;
89         external::ResizeData   resizedata;
90         external::RotationData rotationdata;
91
92         /** if \c true, simply output the filename, maybe wrapped in a
93          *  box, rather than generate and display the image etc.
94          */
95         bool draft;
96
97 private:
98         external::TempName tempname_;
99         std::string templatename_;
100 };
101
102
103 class RenderBase;
104
105 ///
106 class InsetExternal : public Inset, public boost::signals::trackable
107 {
108 public:
109         InsetExternal(Buffer &);
110         ///
111         ~InsetExternal();
112         ///
113         static void string2params(std::string const &, Buffer const &,
114                                   InsetExternalParams &);
115         ///
116         static std::string params2string(InsetExternalParams const &,
117                                                Buffer const &);
118         ///
119         InsetExternalParams const & params() const;
120         ///
121         void setParams(InsetExternalParams const &);
122         ///
123         void setBuffer(Buffer & buffer);
124         /// \returns the number of rows (\n's) of generated code.
125         int latex(odocstream &, OutputParams const &) const;
126
127 private:
128         ///
129         InsetExternal(InsetExternal const &);
130         ///
131         InsetCode lyxCode() const { return EXTERNAL_CODE; }
132         ///
133         EDITABLE editable() const { return IS_EDITABLE; }
134         ///
135         void metrics(MetricsInfo &, Dimension &) const;
136         ///
137         void draw(PainterInfo & pi, int x, int y) const;
138         ///
139         void write(std::ostream &) const;
140         ///
141         void read(Lexer & lex);
142         ///
143         int plaintext(odocstream &, OutputParams const &) const;
144         ///
145         int docbook(odocstream &, OutputParams const &) const;
146         /// Update needed features for this inset.
147         void validate(LaTeXFeatures & features) const;
148         ///
149         void addPreview(graphics::PreviewLoader &) const;
150         ///
151         void edit(Cursor & cur, bool front, EntryDirection entry_from);
152         ///
153         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
154         /// external file can be embedded
155         void registerEmbeddedFiles(EmbeddedFileList &) const;
156         ///
157         void updateEmbeddedFile(EmbeddedFile const &);
158         ///
159         void doDispatch(Cursor & cur, FuncRequest & cmd);
160         ///
161         Inset * clone() const { return new InsetExternal(*this); }
162         /** This method is connected to the graphics loader, so we are
163          *  informed when the image has been loaded.
164          */
165         void statusChanged() const;
166         /** Slot receiving a signal that the external file has changed
167          *  and the preview should be regenerated.
168          */
169         void fileChanged() const;
170
171         /// The current params
172         InsetExternalParams params_;
173         /// The thing that actually draws the image on LyX's screen.
174         boost::scoped_ptr<RenderBase> renderer_;
175 };
176
177 } // namespace lyx
178
179 #endif // INSET_EXTERNAL_H