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