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