]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
Fix bug #6315: counters in insets that don't produce output have ghost values.
[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 public:
39         ///
40         InsetInclude(Buffer * buf, InsetCommandParams const &);
41         ///
42         ~InsetInclude();
43
44         ///
45         void setChildBuffer(Buffer * buffer);
46         /// \return the child buffer if the file is a LyX doc and could be loaded
47         Buffer * getChildBuffer() const;
48
49         /** Update the cache with all bibfiles in use of the child buffer
50          *  (including bibfiles of grandchild documents).
51          *  Does nothing if the child document is not loaded to prevent
52          *  automatic loading of all child documents upon loading the master.
53          *  \param buffer the Buffer containing this inset.
54          */
55         void updateBibfilesCache();
56
57         /** Return the cache with all bibfiles in use of the child buffer
58          *  (including bibfiles of grandchild documents).
59          *  Return an empty vector if the child doc is not loaded.
60          *  \param buffer the Buffer containing this inset.
61          */
62         support::FileNameList const &
63                 getBibfilesCache() const;
64
65         ///
66         void updateCommand();
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         /** Fills \c key
83          *  \param keys the list of bibkeys in the child buffer.
84          *  \param it not used here
85          */
86         void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
87         ///
88         bool hasSettings() const { return true; }
89         ///
90         int latex(odocstream &, OutputParams const &) const;
91         ///
92         int plaintext(odocstream &, OutputParams const &) const;
93         ///
94         int docbook(odocstream &, OutputParams const &) const;
95         ///
96         docstring xhtml(XHTMLStream &, OutputParams const &) const;
97         ///
98         void validate(LaTeXFeatures &) const;
99         ///
100         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
101         ///
102         void addToToc(DocIterator const &);
103         ///
104         void updateBuffer(ParIterator const &, UpdateType);
105         ///
106         docstring contextMenu(BufferView const & bv, int x, int y) const;
107         //@}
108
109         /// \name Static public methods obligated for InsetCommand derived classes
110         //@{
111         ///
112         static ParamInfo const & findInfo(std::string const &);
113         ///
114         static std::string defaultCommand() { return "include"; }
115         ///
116         static bool isCompatibleCommand(std::string const & s);
117         //@}
118
119 protected:
120         ///
121         InsetInclude(InsetInclude const &);
122
123 private:
124         /** Slot receiving a signal that the external file has changed
125          *  and the preview should be regenerated.
126          */
127         void fileChanged() const;
128         /// \return loaded Buffer or zero if the file loading did not proceed.
129         Buffer * loadIfNeeded() const;
130         /// launch external application
131         void editIncluded(std::string const & file);
132         ///
133         bool isChildIncluded() const;
134
135         /// \name Private functions inherited from Inset class
136         //@{
137         Inset * clone() const { return new InsetInclude(*this); }
138         ///
139         void doDispatch(Cursor & cur, FuncRequest & cmd);
140         ///
141         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
142         //@}
143
144         /// \name Private functions inherited from InsetCommand class
145         //@{
146         /// set the parameters
147         // FIXME:InsetCommmand::setParams is not virtual
148         void setParams(InsetCommandParams const & params);
149         /// get the text displayed on the button
150         docstring screenLabel() const;
151         //@}    
152         
153         /// holds the entity name that defines the file location (SGML)
154         docstring const include_label;
155
156         /// The pointer never changes although *preview_'s contents may.
157         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
158
159         /// 
160         mutable bool failedtoload_;
161         /// cache
162         mutable bool set_label_;
163         mutable RenderButton button_;
164         mutable docstring listings_label_;
165         InsetLabel * label_;
166         mutable Buffer * child_buffer_;
167 };
168
169
170 } // namespace lyx
171
172 #endif // INSET_INCLUDE_H