]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
fe35b5abbf3762aa5fccfdd96955ab2255d5b68a
[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 InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
97         ///
98         virtual EDITABLE editable() const { return IS_EDITABLE; }
99
100         ///
101         void metrics(MetricsInfo &, Dimension &) const;
102         ///
103         void draw(PainterInfo & pi, int x, int y) const;
104         ///
105         virtual void write(Buffer const &, std::ostream &) const;
106         ///
107         virtual void read(Buffer const &, LyXLex & lex);
108
109         /// \returns the number of rows (\n's) of generated code.
110         virtual int latex(Buffer const &, std::ostream &,
111                           LatexRunParams const &) const;
112         ///
113         virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
114         ///
115         virtual int linuxdoc(Buffer const &, std::ostream &) const;
116         ///
117         virtual int docbook(Buffer const &, std::ostream &,
118                             bool mixcont) const;
119
120         /// Update needed features for this inset.
121         virtual void validate(LaTeXFeatures & features) const;
122
123         ///
124         InsetExternalParams const & params() const;
125         void setParams(InsetExternalParams const &, Buffer const &);
126 protected:
127         ///
128         virtual
129         dispatch_result
130         priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
131 private:
132         /** This method is connected to the graphics loader, so we are
133          *  informed when the image has been loaded.
134          */
135         void statusChanged() const;
136
137         /// The current params
138         InsetExternalParams params_;
139         /// The thing that actually draws the image on LyX's screen.
140         boost::scoped_ptr<RenderBase> renderer_;
141 };
142
143
144 #include "mailinset.h"
145
146 class InsetExternalMailer : public MailInset {
147 public:
148         ///
149         InsetExternalMailer(InsetExternal & inset);
150         ///
151         virtual InsetBase & inset() const { return inset_; }
152         ///
153         virtual std::string const & name() const { return name_; }
154         ///
155         virtual std::string const inset2string(Buffer const &) const;
156         ///
157         static void string2params(std::string const &, Buffer const &,
158                                   InsetExternalParams &);
159         ///
160         static std::string const params2string(InsetExternalParams const &,
161                                                Buffer const &);
162 private:
163         ///
164         static std::string const name_;
165         ///
166         InsetExternal & inset_;
167 };
168
169 #endif