]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
92323646fbaec0fcc4971f140862703fde077d15
[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 "renderers.h"
17 #include <boost/scoped_ptr.hpp>
18
19
20 class Buffer;
21 class Dimension;
22 struct LaTeXFeatures;
23
24 // Created by AAS 970521
25
26 /// for including tex/lyx files
27 class InsetInclude: public InsetOld {
28 public:
29         struct Params {
30                 Params(InsetCommandParams const & cp = InsetCommandParams("input"),
31                        string const & name = string())
32                         : cparams(cp),
33                           masterFilename_(name) {}
34
35                 InsetCommandParams cparams;
36                 string masterFilename_;
37         };
38
39         ///
40         InsetInclude(Params const &);
41         InsetInclude(InsetCommandParams const &, Buffer const &);
42         InsetInclude(InsetInclude const &);
43
44         ~InsetInclude();
45
46         ///
47         virtual dispatch_result localDispatch(FuncRequest const & cmd);
48
49         /// Override these InsetButton methods if Previewing
50         void metrics(MetricsInfo & mi, Dimension & dim) const;
51         ///
52         void draw(PainterInfo & pi, int x, int y) const;
53         ///
54         virtual BufferView * view() const;
55
56         /// get the parameters
57         Params const & params(void) const;
58         /// set the parameters
59         void set(Params const & params);
60
61         ///
62         virtual std::auto_ptr<InsetBase> clone() const;
63         ///
64         InsetOld::Code lyxCode() const { return InsetOld::INCLUDE_CODE; }
65         /// This returns the list of labels on the child buffer
66         void getLabelList(std::vector<string> &) const;
67         /// This returns the list of bibkeys on the child buffer
68         void fillWithBibKeys(std::vector<std::pair<string,string> > & keys) const;
69         ///
70         EDITABLE editable() const
71         {
72                 return IS_EDITABLE;
73         }
74         ///
75         void write(Buffer const &, std::ostream &) const;
76         ///
77         void read(Buffer const &, LyXLex &);
78         ///
79         int latex(Buffer const &, std::ostream &,
80                   LatexRunParams const &) const;
81         ///
82         int ascii(Buffer const &, std::ostream &, int linelen) const;
83         ///
84         int linuxdoc(Buffer const &, std::ostream &) const;
85         ///
86         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
87         ///
88         void validate(LaTeXFeatures &) const;
89
90         /// return true if the file is or got loaded.
91         bool loadIfNeeded() const;
92
93         ///
94         void addPreview(lyx::graphics::PreviewLoader &) const;
95
96 private:
97         friend class InsetIncludeMailer;
98
99         ///
100         void write(std::ostream &) const;
101         ///
102         void read(LyXLex &);
103         /// get the text displayed on the button
104         string const getScreenLabel(Buffer const &) const;
105         /// get the filename of the master buffer
106         string const getMasterFilename() const;
107         /// get the included file name
108         string const getFileName() const;
109
110         /// the parameters
111         Params params_;
112         /// holds the entity name that defines the file location (SGML)
113         string const include_label;
114
115         /// Use the Pimpl idiom to hide the internals of the previewer.
116         class PreviewImpl;
117         friend class PreviewImpl;
118         /// The pointer never changes although *preview_'s contents may.
119         boost::scoped_ptr<PreviewImpl> const preview_;
120
121         /// cache
122         mutable bool set_label_;
123         mutable ButtonRenderer button_;
124 };
125
126
127 #include "mailinset.h"
128
129 class InsetIncludeMailer : public MailInset {
130 public:
131         ///
132         InsetIncludeMailer(InsetInclude & inset);
133         ///
134         virtual InsetBase & inset() const { return inset_; }
135         ///
136         virtual string const & name() const { return name_; }
137         ///
138         virtual string const inset2string(Buffer const &) const;
139         ///
140         static void string2params(string const &, InsetInclude::Params &);
141         ///
142         static string const params2string(InsetInclude::Params const &);
143 private:
144         ///
145         static string const name_;
146         ///
147         InsetInclude & inset_;
148 };
149
150 #endif // INSETINCLUDE_H