]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
9e955d1b76214a8105be3d99ea154e86e3d863b8
[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
17 #include "graphics/GraphicsTypes.h"
18
19 #include "support/filename.h"
20
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
23
24
25 class RenderInset;
26
27 ///
28 class InsetExternal : public InsetOld, public boost::signals::trackable
29 {
30         /** No two Params variables can have the same temporary file.
31          *  This struct has copy-semantics but the copy constructor
32          *  and assignment operator simply call the default constructor.
33          *  Use of this struct enables us to use the compiler-generated
34          *  copy constructor and assignment operator for the Params struct.
35          */
36         struct TempName {
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 public:
47         /// hold parameters settable from the GUI
48         struct Params {
49                 Params();
50
51                 void write(Buffer const &, std::ostream &) const;
52                 bool read(Buffer const &, LyXLex &);
53
54                 /// The name of the tempfile used for manipulations.
55                 std::string const & tempname() const { return tempname_(); }
56
57                 /// the current template used
58                 void settemplate(std::string const &);
59                 std::string const & templatename() const { return templatename_; }
60
61                 /// the filename
62                 lyx::support::FileName filename;
63                 /// how the inset is displayed by LyX
64                 lyx::graphics::DisplayType display;
65                 /// The scale of the displayed graphic (If shown).
66                 unsigned int lyxscale;
67
68         private:
69                 TempName tempname_;
70                 std::string templatename_;
71         };
72
73         InsetExternal();
74         ///
75         InsetExternal(InsetExternal const &);
76         ///
77         virtual ~InsetExternal();
78         ///
79         virtual dispatch_result localDispatch(FuncRequest const & cmd);
80         ///
81         void metrics(MetricsInfo &, Dimension &) const;
82         ///
83         void draw(PainterInfo & pi, int x, int y) const;
84         ///
85         virtual EDITABLE editable() const { return IS_EDITABLE; }
86         ///
87         virtual void write(Buffer const &, std::ostream &) const;
88         ///
89         virtual void read(Buffer const &, LyXLex & lex);
90
91         /** returns the number of rows (\n's) of generated tex code.
92          fragile == true means, that the inset should take care about
93          fragile commands by adding a \protect before.
94          If the free_spc (freespacing) variable is set, then this inset
95          is in a free-spacing paragraph.
96          */
97         virtual int latex(Buffer const &, std::ostream &,
98                           LatexRunParams const &) const;
99         /// write ASCII output to the ostream
100         virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
101         /// write LinuxDoc output to the ostream
102         virtual int linuxdoc(Buffer const &, std::ostream &) const;
103         /// write DocBook output to the ostream
104         virtual int docbook(Buffer const &, std::ostream &, bool mixcont) const;
105
106         /// Updates needed features for this inset.
107         virtual void validate(LaTeXFeatures & features) const;
108
109         /// returns LyX code associated with the inset. Used for TOC, ...)
110         virtual InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
111
112         ///
113         virtual std::auto_ptr<InsetBase> clone() const;
114
115         /// return a copy of our current params
116         Params const & params() const;
117
118         /// Set the inset parameters.
119         virtual void setParams(Params const &, Buffer const &);
120
121         /** update the file represented by the template.
122             If \param external_in_tmpdir == true, then the generated file is
123             place in the buffer's temporary directory.
124         */
125         void updateExternal(std::string const &, Buffer const &,
126                             bool external_in_tmpdir) const;
127
128 private:
129         /** This method is connected to the graphics loader, so we are
130          *  informed when the image has been loaded.
131          */
132         void statusChanged();
133
134         /** Write the output for a specific file format
135             and generate any external data files.
136             If \param external_in_tmpdir == true, then the generated file is
137             place in the buffer's temporary directory.
138         */
139         int write(std::string const & format, Buffer const &, std::ostream &,
140                   bool external_in_tmpdir = false) const;
141
142         /// the current params
143         Params params_;
144
145         /// The thing that actually draws the image on LyX's screen.
146         boost::scoped_ptr<RenderInset> renderer_;
147 };
148
149
150 #include "mailinset.h"
151
152 class InsetExternalMailer : public MailInset {
153 public:
154         ///
155         InsetExternalMailer(InsetExternal & inset);
156         ///
157         virtual InsetBase & inset() const { return inset_; }
158         ///
159         virtual std::string const & name() const { return name_; }
160         ///
161         virtual std::string const inset2string(Buffer const &) const;
162         ///
163         static void string2params(std::string const &, Buffer const &,
164                                   InsetExternal::Params &);
165         ///
166         static std::string const params2string(InsetExternal::Params const &,
167                                           Buffer const &);
168 private:
169         ///
170         static std::string const name_;
171         ///
172         InsetExternal & inset_;
173 };
174
175 #endif