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