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