]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
* Rename InsetExternal::Params as InsetExternalParams. Consistent with
[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
17 #include "graphics/GraphicsTypes.h"
18
19 #include "support/filename.h"
20
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
23
24
25 /** No two InsetExternalParams variables can have the same temporary file.
26  *  This struct has copy-semantics but the copy constructor
27  *  and assignment operator simply call the default constructor.
28  *  Use of this struct enables us to use the compiler-generated
29  *  copy constructor and assignment operator for the
30  *  InsetExternalParams struct.
31  */
32 namespace lyx {
33 namespace external {
34
35 struct TempName {
36         TempName();
37         TempName(TempName const &);
38         ~TempName();
39         TempName & operator=(TempName const &);
40         std::string const & operator()() const { return tempname_; }
41 private:
42         std::string tempname_;
43 };
44
45 } // namespace external
46 } // namespace lyx
47
48
49 /// hold parameters settable from the GUI
50 struct InsetExternalParams {
51         InsetExternalParams();
52
53         void write(Buffer const &, std::ostream &) const;
54         bool read(Buffer const &, LyXLex &);
55
56         /// The name of the tempfile used for manipulations.
57         std::string const & tempname() const { return tempname_(); }
58
59         /// The template currently in use.
60         void settemplate(std::string const &);
61         std::string const & templatename() const { return templatename_; }
62
63         /// The external file.
64         lyx::support::FileName filename;
65         /// How the inset is to be displayed by LyX.
66         lyx::graphics::DisplayType display;
67         /// The scale of the displayed graphic (if shown).
68         unsigned int lyxscale;
69
70 private:
71         lyx::external::TempName tempname_;
72         std::string templatename_;
73 };
74
75
76 class RenderInset;
77
78 ///
79 class InsetExternal : public InsetOld, public boost::signals::trackable
80 {
81 public:
82         InsetExternal();
83         ///
84         InsetExternal(InsetExternal const &);
85         ///
86         virtual ~InsetExternal();
87         ///
88         virtual std::auto_ptr<InsetBase> clone() const;
89         ///
90         virtual dispatch_result localDispatch(FuncRequest const & cmd);
91
92         ///
93         virtual InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
94         ///
95         virtual EDITABLE editable() const { return IS_EDITABLE; }
96
97         ///
98         void metrics(MetricsInfo &, Dimension &) const;
99         ///
100         void draw(PainterInfo & pi, int x, int y) const;
101         ///
102         virtual void write(Buffer const &, std::ostream &) const;
103         ///
104         virtual void read(Buffer const &, LyXLex & lex);
105
106         /// \returns the number of rows (\n's) of generated code.
107         virtual int latex(Buffer const &, std::ostream &,
108                           LatexRunParams const &) const;
109         ///
110         virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
111         ///
112         virtual int linuxdoc(Buffer const &, std::ostream &) const;
113         ///
114         virtual int docbook(Buffer const &, std::ostream &,
115                             bool mixcont) const;
116
117         /// Update needed features for this inset.
118         virtual void validate(LaTeXFeatures & features) const;
119
120         ///
121         InsetExternalParams const & params() const;
122         void setParams(InsetExternalParams const &, Buffer const &);
123
124 private:
125         /** This method is connected to the graphics loader, so we are
126          *  informed when the image has been loaded.
127          */
128         void statusChanged();
129
130         /// The current params
131         InsetExternalParams params_;
132         /// The thing that actually draws the image on LyX's screen.
133         boost::scoped_ptr<RenderInset> renderer_;
134 };
135
136
137 #include "mailinset.h"
138
139 class InsetExternalMailer : public MailInset {
140 public:
141         ///
142         InsetExternalMailer(InsetExternal & inset);
143         ///
144         virtual InsetBase & inset() const { return inset_; }
145         ///
146         virtual std::string const & name() const { return name_; }
147         ///
148         virtual std::string const inset2string(Buffer const &) const;
149         ///
150         static void string2params(std::string const &, Buffer const &,
151                                   InsetExternalParams &);
152         ///
153         static std::string const params2string(InsetExternalParams const &,
154                                                Buffer const &);
155 private:
156         ///
157         static std::string const name_;
158         ///
159         InsetExternal & inset_;
160 };
161
162 #endif