]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
setFont rework + some code simplification
[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 "support/filename.h"
19 #include "support/translator.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 /// How is the image to be displayed on the LyX screen?
46 enum DisplayType {
47         DefaultDisplay,
48         MonochromeDisplay,
49         GrayscaleDisplay,
50         ColorDisplay,
51         PreviewDisplay,
52         NoDisplay
53 };
54
55
56 /// The translator between the Display enum and corresponding lyx string.
57 Translator<DisplayType, std::string> const & displayTranslator();
58
59 } // namespace external
60 } // namespace lyx
61
62
63 /// hold parameters settable from the GUI
64 struct InsetExternalParams {
65         InsetExternalParams();
66
67         void write(Buffer const &, std::ostream &) const;
68         bool read(Buffer const &, LyXLex &);
69
70         /// The name of the tempfile used for manipulations.
71         std::string const & tempname() const { return tempname_(); }
72
73         /// The template currently in use.
74         void settemplate(std::string const &);
75         std::string const & templatename() const { return templatename_; }
76
77         /// The external file.
78         lyx::support::FileName filename;
79         /// How the inset is to be displayed by LyX.
80         lyx::external::DisplayType display;
81         /// The scale of the displayed graphic (if shown).
82         unsigned int lyxscale;
83
84         lyx::external::ClipData     clipdata;
85         lyx::external::ExtraData    extradata;
86         lyx::external::ResizeData   resizedata;
87         lyx::external::RotationData rotationdata;
88
89 private:
90         lyx::external::TempName tempname_;
91         std::string templatename_;
92 };
93
94
95 class RenderBase;
96
97 ///
98 class InsetExternal : public InsetOld, public boost::signals::trackable
99 {
100 public:
101         InsetExternal();
102         ///
103         InsetExternal(InsetExternal const &);
104         ///
105         virtual ~InsetExternal();
106         ///
107         virtual std::auto_ptr<InsetBase> clone() const;
108         ///
109         virtual InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
110         ///
111         virtual EDITABLE editable() const { return IS_EDITABLE; }
112
113         ///
114         void metrics(MetricsInfo &, Dimension &) const;
115         ///
116         void draw(PainterInfo & pi, int x, int y) const;
117         ///
118         virtual void write(Buffer const &, std::ostream &) const;
119         ///
120         virtual void read(Buffer const &, LyXLex & lex);
121
122         /// \returns the number of rows (\n's) of generated code.
123         virtual int latex(Buffer const &, std::ostream &,
124                           OutputParams const &) const;
125         ///
126         virtual int plaintext(Buffer const &, std::ostream &,
127                           OutputParams const &) const;
128         ///
129         virtual int linuxdoc(Buffer const &, std::ostream &,
130                              OutputParams const &) const;
131         ///
132         virtual int docbook(Buffer const &, std::ostream &,
133                             OutputParams const &) const;
134
135         /// Update needed features for this inset.
136         virtual void validate(LaTeXFeatures & features) const;
137
138         ///
139         InsetExternalParams const & params() const;
140         void setParams(InsetExternalParams const &, Buffer const &);
141         ///
142         void addPreview(lyx::graphics::PreviewLoader &) const;
143         ///
144         void edit(BufferView * bv, bool);
145
146 protected:
147         ///
148         virtual
149         DispatchResult
150         priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
151 private:
152         /** This method is connected to the graphics loader, so we are
153          *  informed when the image has been loaded.
154          */
155         void statusChanged() const;
156
157         /** Slot receiving a signal that the external file has changed
158          *  and the preview should be regenerated.
159          */
160         void fileChanged() const;
161
162         /// The current params
163         InsetExternalParams params_;
164         /// The thing that actually draws the image on LyX's screen.
165         boost::scoped_ptr<RenderBase> renderer_;
166 };
167
168
169 #include "mailinset.h"
170
171 class InsetExternalMailer : public MailInset {
172 public:
173         ///
174         InsetExternalMailer(InsetExternal & inset);
175         ///
176         virtual InsetBase & inset() const { return inset_; }
177         ///
178         virtual std::string const & name() const { return name_; }
179         ///
180         virtual std::string const inset2string(Buffer const &) const;
181         ///
182         static void string2params(std::string const &, Buffer const &,
183                                   InsetExternalParams &);
184         ///
185         static std::string const params2string(InsetExternalParams const &,
186                                                Buffer const &);
187 private:
188         ///
189         static std::string const name_;
190         ///
191         InsetExternal & inset_;
192 };
193
194 #endif