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