]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
83285347febdb0a79c815aac75f9b8dff0384b87
[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                 ~Params();
33                 /// the filename
34                 string filename;
35                 /// The name of the tempfile used for manipulations.
36                 string tempname;
37                 /// the current template used
38                 ExternalTemplate templ;
39                 /// how the inset is displayed by LyX
40                 grfx::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         /// what appears in the minibuffer when opening
57         virtual string const editMessage() const;
58         ///
59         virtual EDITABLE editable() const { return IS_EDITABLE; }
60         ///
61         virtual void write(Buffer const *, std::ostream &) const;
62         ///
63         virtual void read(Buffer const *, LyXLex & lex);
64
65         /** returns the number of rows (\n's) of generated tex code.
66          fragile == true means, that the inset should take care about
67          fragile commands by adding a \protect before.
68          If the free_spc (freespacing) variable is set, then this inset
69          is in a free-spacing paragraph.
70          */
71         virtual int latex(Buffer const *, std::ostream &,
72                           LatexRunParams const &) const;
73         /// write ASCII output to the ostream
74         virtual int ascii(Buffer const *, std::ostream &, int linelen) const;
75         /// write LinuxDoc output to the ostream
76         virtual int linuxdoc(Buffer const *, std::ostream &) const;
77         /// write DocBook output to the ostream
78         virtual int docbook(Buffer const *, std::ostream &, bool mixcont) const;
79
80         /// Updates needed features for this inset.
81         virtual void validate(LaTeXFeatures & features) const;
82
83         /// returns LyX code associated with the inset. Used for TOC, ...)
84         virtual Inset::Code lyxCode() const { return EXTERNAL_CODE; }
85
86         ///
87         virtual Inset * clone() const;
88
89         /// Set the inset parameters.
90         virtual void setParams(Params const &, string const & filepath);
91
92         /** update the file represented by the template.
93             If \param external_in_tmpdir == true, then the generated file is
94             place in the buffer's temporary directory.
95         */
96         void updateExternal(string const &, Buffer const *,
97                             bool external_in_tmpdir) const;
98
99         /// return a copy of our current params
100         Params const & params() const;
101
102 private:
103         /** This method is connected to the graphics loader, so we are
104          *  informed when the image has been loaded.
105          */
106         void statusChanged();
107
108         /** Write the output for a specific file format
109             and generate any external data files.
110             If \param external_in_tmpdir == true, then the generated file is
111             place in the buffer's temporary directory.
112         */
113         int write(string const & format, Buffer const *, std::ostream &,
114                   bool external_in_tmpdir = false) const;
115
116         /// the current params
117         Params params_;
118
119         /// The thing that actually draws the image on LyX's screen.
120         boost::scoped_ptr<GraphicInset> const renderer_;
121 };
122
123
124 #include "mailinset.h"
125
126 class InsetExternalMailer : public MailInset {
127 public:
128         ///
129         InsetExternalMailer(InsetExternal & inset);
130         ///
131         virtual InsetBase & inset() const { return inset_; }
132         ///
133         virtual string const & name() const { return name_; }
134         ///
135         virtual string const inset2string() const;
136         ///
137         static void string2params(string const &, InsetExternal::Params &);
138         ///
139         static string const params2string(InsetExternal::Params const &);
140 private:
141         ///
142         static string const name_;
143         ///
144         InsetExternal & inset_;
145 };
146
147 #endif