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