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