]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
405a4c0c2f5765b0540c22a2f3be2f6980aa2e1d
[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 "BiblioInfo.h"
17 #include "InsetCommand.h"
18 #include "InsetCommandParams.h"
19 #include "RenderButton.h"
20 #include "MailInset.h"
21 #include "Counters.h"
22 #include "EmbeddedFiles.h"
23
24 #include <boost/scoped_ptr.hpp>
25
26 namespace lyx {
27
28 class Buffer;
29 class Dimension;
30 class InsetLabel;
31 class LaTeXFeatures;
32 class RenderMonitoredPreview;
33
34 /// for including tex/lyx files
35 class InsetInclude : public InsetCommand {
36 public:
37         ///
38         InsetInclude(InsetCommandParams const &);
39         ~InsetInclude();
40
41         void setBuffer(Buffer & buffer);
42
43         /// Override these InsetButton methods if Previewing
44         void metrics(MetricsInfo & mi, Dimension & dim) const;
45         ///
46         void draw(PainterInfo & pi, int x, int y) const;
47         ///
48         DisplayType display() const;
49         ///
50         InsetCode lyxCode() const { return INCLUDE_CODE; }
51         /** Fills \c keys
52          *  \param buffer the Buffer containing this inset.
53          *  \param keys the list of bibkeys in the child buffer.
54          *  \param it not used here
55          */
56         void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
57         
58         /** Update the cache with all bibfiles in use of the child buffer
59          *  (including bibfiles of grandchild documents).
60          *  Does nothing if the child document is not loaded to prevent
61          *  automatic loading of all child documents upon loading the master.
62          *  \param buffer the Buffer containing this inset.
63          */
64         void updateBibfilesCache();
65         /** Return the cache with all bibfiles in use of the child buffer
66          *  (including bibfiles of grandchild documents).
67          *  Return an empty vector if the child doc is not loaded.
68          *  \param buffer the Buffer containing this inset.
69          */
70         EmbeddedFileList const &
71                 getBibfilesCache(Buffer const & buffer) const;
72         ///
73         EDITABLE editable() const { return IS_EDITABLE; }
74         ///
75         int latex(odocstream &, OutputParams const &) const;
76         ///
77         int plaintext(odocstream &, OutputParams const &) const;
78         ///
79         int docbook(odocstream &, OutputParams const &) const;
80         ///
81         void validate(LaTeXFeatures &) const;
82         ///
83         void addPreview(graphics::PreviewLoader &) const;
84         ///
85         void addToToc(ParConstIterator const &) const;
86         ///
87         void updateLabels(ParIterator const &);
88         /// child document can be embedded
89         void registerEmbeddedFiles(EmbeddedFileList &) const;
90         ///
91         void updateEmbeddedFile(EmbeddedFile const & file);
92         ///
93         static ParamInfo const & findInfo(std::string const &);
94         ///
95         static std::string defaultCommand() { return "include"; };
96         ///
97         static bool isCompatibleCommand(std::string const & s);
98 protected:
99         InsetInclude(InsetInclude const &);
100         ///
101         void doDispatch(Cursor & cur, FuncRequest & cmd);
102 private:
103         Inset * clone() const { return new InsetInclude(*this); }
104
105         /** Slot receiving a signal that the external file has changed
106          *  and the preview should be regenerated.
107          */
108         void fileChanged() const;
109
110         /// set the parameters
111         void setParams(InsetCommandParams const & params);
112         /// get the text displayed on the button
113         docstring screenLabel() const;
114         /// holds the entity name that defines the file location (SGML)
115         docstring const include_label;
116
117         /// The pointer never changes although *preview_'s contents may.
118         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
119
120         /// cache
121         mutable bool set_label_;
122         mutable RenderButton button_;
123         mutable docstring listings_label_;
124         InsetLabel * label_;
125 };
126
127 /// return loaded Buffer or zero if the file loading did not proceed.
128 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
129
130 } // namespace lyx
131
132 #endif // INSETINCLUDE_H