]> git.lyx.org Git - features.git/blob - src/insets/InsetInclude.h
Rename XHTMLStream to XMLStream, move it to another file, and prepare for DocBook...
[features.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  * \author Richard Heck (conversion to InsetCommand)
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_INCLUDE_H
14 #define INSET_INCLUDE_H
15
16 #include "InsetCommand.h"
17
18 #include "RenderButton.h"
19
20 #include "support/unique_ptr.h"
21
22
23 namespace lyx {
24
25 class BiblioInfo;
26 class Buffer;
27 class Dimension;
28 class InsetCommandParams;
29 class InsetLabel;
30 class LaTeXFeatures;
31 class RenderMonitoredPreview;
32
33 namespace support {
34         class FileNameList;
35 }
36
37 /// for including tex/lyx files
38 class InsetInclude : public InsetCommand {
39         // Disable assignment operator, since it is not used, and cannot be
40         // implemented consistently with the copy constructor, because
41         // include_label is const.
42         InsetInclude & operator=(InsetInclude const &);
43 public:
44         ///
45         InsetInclude(Buffer * buf, InsetCommandParams const &);
46         ///
47         ~InsetInclude();
48
49         ///
50         void setChildBuffer(Buffer * buffer);
51
52         /// \return loaded Buffer or zero if the file loading did not proceed.
53         Buffer * loadIfNeeded() const;
54
55         /** Update the cache with all bibfiles in use of the child buffer
56          *  (including bibfiles of grandchild documents).
57          *  Does nothing if the child document is not loaded to prevent
58          *  automatic loading of all child documents upon loading the master.
59          *  \param buffer the Buffer containing this inset.
60          */
61         void updateBibfilesCache();
62
63         ///
64         void updateCommand();
65         ///
66         void write(std::ostream &) const;
67
68         /// \name Public functions inherited from Inset class
69         //@{
70         ///
71         void setBuffer(Buffer & buffer);
72         ///
73         bool isLabeled() const { return true; }
74         /// Override these InsetButton methods if Previewing
75         void metrics(MetricsInfo & mi, Dimension & dim) const;
76         ///
77         void draw(PainterInfo & pi, int x, int y) const;
78         ///
79         DisplayType display() const;
80         ///
81         InsetCode lyxCode() const { return INCLUDE_CODE; }
82         ///
83         docstring layoutName() const;
84         /** Fills \c key
85          *  \param keys the list of bibkeys in the child buffer.
86          *  \param it not used here
87          */
88         void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
89         ///
90         bool hasSettings() const { return true; }
91         ///
92         void latex(otexstream &, OutputParams const &) const;
93         ///
94         int plaintext(odocstringstream & ods, OutputParams const & op,
95                       size_t max_length = INT_MAX) const;
96         ///
97         int docbook(odocstream &, OutputParams const &) const;
98         ///
99         docstring xhtml(XMLStream &, OutputParams const &) const;
100         ///
101         void validate(LaTeXFeatures &) const;
102         ///
103         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
104         ///
105         void addToToc(DocIterator const & di, bool output_active,
106                                   UpdateType utype, TocBackend & backend) const;
107         ///
108         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
109         ///
110         std::string contextMenuName() const;
111         //@}
112
113         /// \name Static public methods obligated for InsetCommand derived classes
114         //@{
115         ///
116         static ParamInfo const & findInfo(std::string const &);
117         ///
118         static std::string defaultCommand() { return "include"; }
119         ///
120         static bool isCompatibleCommand(std::string const & s);
121         ///
122         bool needsCProtection(bool const maintext = false,
123                               bool const fragile = false) const;
124         //@}
125
126 protected:
127         ///
128         InsetInclude(InsetInclude const &);
129
130 private:
131         /** Slot receiving a signal that the external file has changed
132          *  and the preview should be regenerated.
133          */
134         void fileChanged() const;
135         /// launch external application
136         void editIncluded(std::string const & file);
137         ///
138         bool isChildIncluded() const;
139         /// check whether the included file exist
140         bool includedFileExist() const;
141         /// \return True if there is a recursive include
142         /// Also issues appropriate warning, etc
143         bool checkForRecursiveInclude(Buffer const * cbuf, bool silent = false) const;
144
145         /// \name Private functions inherited from Inset class
146         //@{
147         Inset * clone() const { return new InsetInclude(*this); }
148         ///
149         void doDispatch(Cursor & cur, FuncRequest & cmd);
150         ///
151         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
152         //@}
153
154         /// \name Private functions inherited from InsetCommand class
155         //@{
156         /// set the parameters
157         // FIXME:InsetCommmand::setParams is not virtual
158         void setParams(InsetCommandParams const & params);
159         /// get the text displayed on the button
160         docstring screenLabel() const;
161         //@}
162         
163         /// holds the entity name that defines the file location (XML)
164         docstring const include_label;
165
166         /// The pointer never changes although *preview_'s contents may.
167         unique_ptr<RenderMonitoredPreview> const preview_;
168
169         ///
170         mutable bool failedtoload_;
171         /// cache
172         mutable bool set_label_;
173         mutable RenderButton button_;
174         mutable docstring listings_label_;
175         InsetLabel * label_;
176         mutable Buffer * child_buffer_;
177         mutable bool file_exist_;
178         mutable bool recursion_error_;
179 };
180
181
182 } // namespace lyx
183
184 #endif // INSET_INCLUDE_H