]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
The speed patch: redraw only rows that have changed
[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 namespace external {
34
35 class TempName {
36 public:
37         TempName();
38         TempName(TempName const &);
39         ~TempName();
40         TempName & operator=(TempName const &);
41         std::string const & operator()() const { return tempname_; }
42 private:
43         std::string tempname_;
44 };
45
46 /// How is the image to be displayed on the LyX screen?
47 enum DisplayType {
48         DefaultDisplay,
49         MonochromeDisplay,
50         GrayscaleDisplay,
51         ColorDisplay,
52         PreviewDisplay,
53         NoDisplay
54 };
55
56
57 /// The translator between the Display enum and corresponding lyx string.
58 Translator<DisplayType, std::string> const & displayTranslator();
59
60 } // namespace external
61 } // namespace lyx
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 &, LyXLex &);
71
72         /// The name of the tempfile used for manipulations.
73         std::string 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         lyx::support::FileName filename;
81         /// How the inset is to be displayed by LyX.
82         lyx::external::DisplayType display;
83         /// The scale of the displayed graphic (if shown).
84         unsigned int lyxscale;
85
86         lyx::external::ClipData     clipdata;
87         lyx::external::ExtraData    extradata;
88         lyx::external::ResizeData   resizedata;
89         lyx::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         lyx::external::TempName tempname_;
98         std::string templatename_;
99 };
100
101
102 class RenderBase;
103
104 ///
105 class InsetExternal : public InsetOld, public boost::signals::trackable
106 {
107 public:
108         InsetExternal();
109         ///
110         virtual ~InsetExternal();
111         ///
112         virtual InsetBase::Code lyxCode() const { return EXTERNAL_CODE; }
113         ///
114         virtual EDITABLE editable() const { return IS_EDITABLE; }
115
116         ///
117         void metrics(MetricsInfo &, Dimension &) const;
118         ///
119         void draw(PainterInfo & pi, int x, int y) const;
120         ///
121         virtual void write(Buffer const &, std::ostream &) const;
122         ///
123         virtual void read(Buffer const &, LyXLex & lex);
124
125         /// \returns the number of rows (\n's) of generated code.
126         virtual int latex(Buffer const &, std::ostream &,
127                           OutputParams const &) const;
128         ///
129         virtual int plaintext(Buffer const &, std::ostream &,
130                           OutputParams const &) const;
131         ///
132         virtual int linuxdoc(Buffer const &, std::ostream &,
133                              OutputParams const &) const;
134         ///
135         virtual int docbook(Buffer const &, std::ostream &,
136                             OutputParams const &) const;
137
138         /// Update needed features for this inset.
139         virtual void validate(LaTeXFeatures & features) const;
140
141         ///
142         InsetExternalParams const & params() const;
143         ///
144         void setParams(InsetExternalParams const &, Buffer const &);
145         ///
146         void addPreview(lyx::graphics::PreviewLoader &) const;
147         ///
148         void edit(LCursor & cur, bool left);
149         ///
150         bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
151
152 protected:
153         InsetExternal(InsetExternal const &);
154         ///
155         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
156 private:
157         virtual std::auto_ptr<InsetBase> doClone() const;
158
159         /** This method is connected to the graphics loader, so we are
160          *  informed when the image has been loaded.
161          */
162         void statusChanged() const;
163
164         /** Slot receiving a signal that the external file has changed
165          *  and the preview should be regenerated.
166          */
167         void fileChanged() const;
168
169         /// The current params
170         InsetExternalParams params_;
171         /// The thing that actually draws the image on LyX's screen.
172         boost::scoped_ptr<RenderBase> renderer_;
173 };
174
175
176 #include "mailinset.h"
177
178 class InsetExternalMailer : public MailInset {
179 public:
180         ///
181         InsetExternalMailer(InsetExternal & inset);
182         ///
183         virtual InsetBase & inset() const { return inset_; }
184         ///
185         virtual std::string const & name() const { return name_; }
186         ///
187         virtual std::string const inset2string(Buffer const &) const;
188         ///
189         static void string2params(std::string const &, Buffer const &,
190                                   InsetExternalParams &);
191         ///
192         static std::string const params2string(InsetExternalParams const &,
193                                                Buffer const &);
194 private:
195         ///
196         static std::string const name_;
197         ///
198         InsetExternal & inset_;
199 };
200
201 #endif