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