]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
Clean up InsetGraphics::Cache and rename as GraphicsInset.
[lyx.git] / src / insets / insetinclude.h
1 // -*- C++ -*-
2 /**
3  * \file insetinclude.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef INSET_INCLUDE_H
13 #define INSET_INCLUDE_H
14
15 #include "insetcommand.h"
16 #include "dimension.h"
17
18 #include <boost/scoped_ptr.hpp>
19
20 class Buffer;
21 struct LaTeXFeatures;
22
23 // Created by AAS 970521
24
25 /// for including tex/lyx files
26 class InsetInclude: public InsetButton, boost::noncopyable {
27 public:
28         /// the type of inclusion
29         enum Flags {
30                 INCLUDE = 0, //<
31                 VERB = 1, //<
32                 INPUT = 2, //<
33                 VERBAST = 3 //<
34         };
35
36         struct Params {
37                 Params(InsetCommandParams const & cp = InsetCommandParams("input"),
38                        Flags f = INPUT,
39                        string const & name = string())
40                         : cparams(cp), flag(f),
41                           masterFilename_(name) {}
42
43                 InsetCommandParams cparams;
44                 Flags flag;
45                 string masterFilename_;
46
47                 ///
48                 bool operator==(Params const &) const;
49                 ///
50                 bool operator!=(Params const &) const;
51         };
52
53         ///
54         InsetInclude(Params const &);
55         ///
56         InsetInclude(InsetCommandParams const &, Buffer const &);
57
58         ~InsetInclude();
59
60         ///
61         virtual dispatch_result localDispatch(FuncRequest const & cmd);
62
63         /// Override these InsetButton methods if Previewing
64         void metrics(MetricsInfo & mi, Dimension & dim) const;
65         ///
66         void draw(PainterInfo & pi, int x, int y) const;
67
68         /// get the parameters
69         Params const & params(void) const;
70         /// set the parameters
71         void set(Params const & params);
72
73         ///
74         virtual Inset * clone() const;
75         ///
76         Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
77         /// This returns the list of labels on the child buffer
78         std::vector<string> const getLabelList() const;
79         /// This returns the list of bibkeys on the child buffer
80         void fillWithBibKeys(std::vector<std::pair<string,string> > & keys) const;
81         ///
82         EDITABLE editable() const
83         {
84                 return IS_EDITABLE;
85         }
86         /// With lyx3 we won't overload these 3 methods
87         void write(Buffer const *, std::ostream &) const;
88         ///
89         void read(Buffer const *, LyXLex &);
90         ///
91         int latex(Buffer const *, std::ostream &,
92                   LatexRunParams const &) const;
93         ///
94         int ascii(Buffer const *, std::ostream &, int linelen) const;
95         ///
96         int linuxdoc(Buffer const *, std::ostream &) const;
97         ///
98         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
99         ///
100         void validate(LaTeXFeatures &) const;
101
102         /// take up a whole row if we're not type INPUT
103         bool display() const;
104
105         /// return true if the file is or got loaded.
106         bool loadIfNeeded() const;
107
108         ///
109         void addPreview(grfx::PreviewLoader &) const;
110
111 private:
112         /// get the text displayed on the button
113         string const getScreenLabel(Buffer const *) const;
114         /// is this a verbatim include ?
115         bool isVerbatim() const;
116         /// get the filename of the master buffer
117         string const getMasterFilename() const;
118         /// get the included file name
119         string const getFileName() const;
120
121         /// the parameters
122         Params params_;
123         /// holds the entity name that defines the file location (SGML)
124         string const include_label;
125
126         /// Use the Pimpl idiom to hide the internals of the previewer.
127         class PreviewImpl;
128         friend class PreviewImpl;
129         /// The pointer never changes although *preview_'s contents may.
130         boost::scoped_ptr<PreviewImpl> const preview_;
131
132         /// cache
133         mutable Dimension dim_;
134 };
135
136
137 inline bool InsetInclude::isVerbatim() const
138 {
139         return params_.flag == VERB || params_.flag == VERBAST;
140 }
141
142 #include "mailinset.h"
143
144 class InsetIncludeMailer : public MailInset {
145 public:
146         ///
147         InsetIncludeMailer(InsetInclude & inset);
148         ///
149         virtual InsetBase & inset() const { return inset_; }
150         ///
151         virtual string const & name() const { return name_; }
152         ///
153         virtual string const inset2string() const;
154         ///
155         static void string2params(string const &, InsetInclude::Params &);
156         ///
157         static string const params2string(InsetInclude::Params const &);
158 private:
159         ///
160         static string const name_;
161         ///
162         InsetInclude & inset_;
163 };
164
165 #endif // INSETINCLUDE_H