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