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