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