]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
b08010c063d3f608e00152dfd7901cab5f8db7a9
[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         /** Fills \c list
66          *  \param buffer the Buffer containing this inset.
67          *  \param list the list of labels in the child buffer.
68          */
69         void getLabelList(Buffer const & buffer,
70                           std::vector<string> & list) const;
71         /** Fills \c keys
72          *  \param buffer the Buffer containing this inset.
73          *  \param keys the list of bibkeys in the child buffer.
74          */
75         ///
76         void fillWithBibKeys(Buffer const & buffer,
77                 std::vector<std::pair<string,string> > & keys) const;
78         ///
79         EDITABLE editable() const
80         {
81                 return IS_EDITABLE;
82         }
83         ///
84         void write(Buffer const &, std::ostream &) const;
85         ///
86         void read(Buffer const &, LyXLex &);
87         ///
88         int latex(Buffer const &, std::ostream &,
89                   LatexRunParams const &) const;
90         ///
91         int ascii(Buffer const &, std::ostream &, int linelen) const;
92         ///
93         int linuxdoc(Buffer const &, std::ostream &) const;
94         ///
95         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
96         ///
97         void validate(LaTeXFeatures &) const;
98
99         ///
100         void addPreview(lyx::graphics::PreviewLoader &) const;
101
102 private:
103         friend class InsetIncludeMailer;
104
105         /// return true if the file is or got loaded.
106         bool loadIfNeeded() const;
107
108         ///
109         void write(std::ostream &) const;
110         ///
111         void read(LyXLex &);
112         /// get the text displayed on the button
113         string const getScreenLabel(Buffer const &) const;
114         /// get the filename of the master buffer
115         string const getMasterFilename() const;
116         /// get the included file name
117         string const getFileName() const;
118
119         /// the parameters
120         Params params_;
121         /// holds the entity name that defines the file location (SGML)
122         string const include_label;
123
124         /// Use the Pimpl idiom to hide the internals of the previewer.
125         class PreviewImpl;
126         friend class PreviewImpl;
127         /// The pointer never changes although *preview_'s contents may.
128         boost::scoped_ptr<PreviewImpl> const preview_;
129
130         /// cache
131         mutable bool set_label_;
132         mutable ButtonRenderer button_;
133 };
134
135
136 #include "mailinset.h"
137
138 class InsetIncludeMailer : public MailInset {
139 public:
140         ///
141         InsetIncludeMailer(InsetInclude & inset);
142         ///
143         virtual InsetBase & inset() const { return inset_; }
144         ///
145         virtual string const & name() const { return name_; }
146         ///
147         virtual string const inset2string(Buffer const &) const;
148         ///
149         static void string2params(string const &, InsetInclude::Params &);
150         ///
151         static string const params2string(InsetInclude::Params const &);
152 private:
153         ///
154         static string const name_;
155         ///
156         InsetInclude & inset_;
157 };
158
159 #endif // INSETINCLUDE_H