]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
Fix date inset except on windows (bug 9925)
[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  * \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 <boost/scoped_ptr.hpp>
21
22 namespace lyx {
23
24 class BiblioInfo;
25 class Buffer;
26 class Dimension;
27 class InsetCommandParams;
28 class InsetLabel;
29 class LaTeXFeatures;
30 class RenderMonitoredPreview;
31
32 namespace support {
33         class FileNameList;
34 }
35
36 /// for including tex/lyx files
37 class InsetInclude : public InsetCommand {
38         // Disable assignment operator, since it is not used, and cannot be
39         // implemented consistently with the copy constructor, because
40         // include_label is const.
41         InsetInclude & operator=(InsetInclude const &);
42 public:
43         ///
44         InsetInclude(Buffer * buf, InsetCommandParams const &);
45         ///
46         ~InsetInclude();
47
48         ///
49         void setChildBuffer(Buffer * buffer);
50         /// \return the child buffer if the file is a LyX doc and could be loaded
51         Buffer * getChildBuffer() const;
52
53         /** Update the cache with all bibfiles in use of the child buffer
54          *  (including bibfiles of grandchild documents).
55          *  Does nothing if the child document is not loaded to prevent
56          *  automatic loading of all child documents upon loading the master.
57          *  \param buffer the Buffer containing this inset.
58          */
59         void updateBibfilesCache();
60
61         /** Return the cache with all bibfiles in use of the child buffer
62          *  (including bibfiles of grandchild documents).
63          *  Return an empty vector if the child doc is not loaded.
64          *  \param buffer the Buffer containing this inset.
65          */
66         support::FileNameList const &
67                 getBibfilesCache() const;
68
69         ///
70         void updateCommand();
71         ///
72         void write(std::ostream &) const;
73
74         /// \name Public functions inherited from Inset class
75         //@{
76         ///
77         void setBuffer(Buffer & buffer);
78         ///
79         bool isLabeled() const { return true; }
80         /// Override these InsetButton methods if Previewing
81         void metrics(MetricsInfo & mi, Dimension & dim) const;
82         ///
83         void draw(PainterInfo & pi, int x, int y) const;
84         ///
85         DisplayType display() const;
86         ///
87         InsetCode lyxCode() const { return INCLUDE_CODE; }
88         ///
89         docstring layoutName() const;
90         /** Fills \c key
91          *  \param keys the list of bibkeys in the child buffer.
92          *  \param it not used here
93          */
94         void collectBibKeys(InsetIterator const &) const;
95         ///
96         bool hasSettings() const { return true; }
97         ///
98         void latex(otexstream &, OutputParams const &) const;
99         ///
100         int plaintext(odocstringstream & ods, OutputParams const & op,
101                       size_t max_length = INT_MAX) const;
102         ///
103         int docbook(odocstream &, OutputParams const &) const;
104         ///
105         docstring xhtml(XHTMLStream &, OutputParams const &) const;
106         ///
107         void validate(LaTeXFeatures &) const;
108         ///
109         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
110         ///
111         void addToToc(DocIterator const & di, bool output_active,
112                                   UpdateType utype) const;
113         ///
114         void updateBuffer(ParIterator const &, UpdateType);
115         ///
116         std::string contextMenuName() const;
117         //@}
118
119         /// \name Static public methods obligated for InsetCommand derived classes
120         //@{
121         ///
122         static ParamInfo const & findInfo(std::string const &);
123         ///
124         static std::string defaultCommand() { return "include"; }
125         ///
126         static bool isCompatibleCommand(std::string const & s);
127         //@}
128
129 protected:
130         ///
131         InsetInclude(InsetInclude const &);
132
133 private:
134         /** Slot receiving a signal that the external file has changed
135          *  and the preview should be regenerated.
136          */
137         void fileChanged() const;
138         /// \return loaded Buffer or zero if the file loading did not proceed.
139         Buffer * loadIfNeeded() const;
140         /// launch external application
141         void editIncluded(std::string const & file);
142         ///
143         bool isChildIncluded() 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 (SGML)
164         docstring const include_label;
165
166         /// The pointer never changes although *preview_'s contents may.
167         boost::scoped_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 };
178
179
180 } // namespace lyx
181
182 #endif // INSET_INCLUDE_H