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