]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
9200fda6afff5292099c69521d99551db7bef944
[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 "BiblioInfo.h"
16 #include "Inset.h"
17 #include "InsetCommandParams.h"
18 #include "RenderButton.h"
19 #include "MailInset.h"
20 #include "Counters.h"
21
22 #include "support/FileName.h"
23
24 #include <boost/scoped_ptr.hpp>
25
26 namespace lyx {
27
28 class Buffer;
29 class Dimension;
30 class LaTeXFeatures;
31 class RenderMonitoredPreview;
32
33
34 /// for including tex/lyx files
35 class InsetInclude : public Inset {
36 public:
37         ///
38         InsetInclude(InsetCommandParams const &);
39         ~InsetInclude();
40
41         /// Override these InsetButton methods if Previewing
42         bool metrics(MetricsInfo & mi, Dimension & dim) const;
43         ///
44         void draw(PainterInfo & pi, int x, int y) const;
45         ///
46         virtual DisplayType display() const;
47
48         /// get the parameters
49         InsetCommandParams const & params() const;
50
51         ///
52         Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
53         /** Fills \c list
54          *  \param buffer the Buffer containing this inset.
55          *  \param list the list of labels in the child buffer.
56          */
57         void getLabelList(Buffer const & buffer,
58                           std::vector<docstring> & list) const;
59         /** Fills \c keys
60          *  \param buffer the Buffer containing this inset.
61          *  \param keys the list of bibkeys in the child buffer.
62          *  \param it not used here
63          */
64         virtual void fillWithBibKeys(Buffer const & buffer,
65                 BiblioInfo & keys, InsetIterator const & it) const;
66         
67         /** Update the cache with all bibfiles in use of the child buffer
68          *  (including bibfiles of grandchild documents).
69          *  Does nothing if the child document is not loaded to prevent
70          *  automatic loading of all child documents upon loading the master.
71          *  \param buffer the Buffer containing this inset.
72          */
73         void updateBibfilesCache(Buffer const & buffer);
74         /** Return the cache with all bibfiles in use of the child buffer
75          *  (including bibfiles of grandchild documents).
76          *  Return an empty vector if the child doc is not loaded.
77          *  \param buffer the Buffer containing this inset.
78          */
79         std::vector<support::FileName> const &
80         getBibfilesCache(Buffer const & buffer) const;
81         ///
82         EDITABLE editable() const { return IS_EDITABLE; }
83         ///
84         void write(Buffer const &, std::ostream &) const;
85         ///
86         void read(Buffer const &, Lexer &);
87         ///
88         int latex(Buffer const &, odocstream &,
89                   OutputParams const &) const;
90         ///
91         int plaintext(Buffer const &, odocstream &,
92                       OutputParams const &) const;
93         ///
94         int docbook(Buffer const &, odocstream &,
95                     OutputParams const &) const;
96         ///
97         void validate(LaTeXFeatures &) const;
98         ///
99         void addPreview(graphics::PreviewLoader &) const;
100         ///
101         void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
102         ///
103         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
104         ///
105         void updateLabels(Buffer const & buffer, ParIterator const &);
106 protected:
107         InsetInclude(InsetInclude const &);
108         ///
109         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
110 private:
111         virtual std::auto_ptr<Inset> doClone() const;
112
113         /** Slot receiving a signal that the external file has changed
114          *  and the preview should be regenerated.
115          */
116         void fileChanged() const;
117
118         friend class InsetIncludeMailer;
119
120         /// set the parameters
121         void set(InsetCommandParams const & params, Buffer const &);
122         /// get the text displayed on the button
123         docstring const getScreenLabel(Buffer const &) const;
124         ///
125         void write(std::ostream &) const;
126         ///
127         void read(Lexer &);
128
129         /// the parameters
130         InsetCommandParams params_;
131         /// holds the entity name that defines the file location (SGML)
132         docstring const include_label;
133
134         /// The pointer never changes although *preview_'s contents may.
135         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
136
137         /// cache
138         mutable bool set_label_;
139         mutable RenderButton button_;
140         mutable docstring listings_label_;
141 };
142
143
144 class InsetIncludeMailer : public MailInset {
145 public:
146         ///
147         InsetIncludeMailer(InsetInclude & inset);
148         ///
149         virtual Inset & inset() const { return inset_; }
150         ///
151         virtual std::string const & name() const { return name_; }
152         ///
153         virtual std::string const inset2string(Buffer const &) const;
154         ///
155         static void string2params(std::string const &, InsetCommandParams &);
156         ///
157         static std::string const params2string(InsetCommandParams const &);
158 private:
159         ///
160         static std::string const name_;
161         ///
162         InsetInclude & inset_;
163 };
164
165 /// return loaded Buffer or zero if the file loading did not proceed.
166 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
167
168 } // namespace lyx
169
170 #endif // INSETINCLUDE_H