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