]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
4eb0409269e0a4ace1c26ff9876cd6071227083d
[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  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSET_INCLUDE_H
13 #define INSET_INCLUDE_H
14
15 #include "Inset.h"
16 #include "InsetCommandParams.h"
17 #include "RenderButton.h"
18 #include "MailInset.h"
19 #include "Counters.h"
20
21 #include "support/FileName.h"
22
23 #include <boost/scoped_ptr.hpp>
24
25 namespace lyx {
26
27 class Buffer;
28 class Dimension;
29 class LaTeXFeatures;
30 class RenderMonitoredPreview;
31
32
33 /// for including tex/lyx files
34 class InsetInclude : public Inset {
35 public:
36         ///
37         InsetInclude(InsetCommandParams const &);
38         ~InsetInclude();
39
40         /// Override these InsetButton methods if Previewing
41         bool metrics(MetricsInfo & mi, Dimension & dim) const;
42         ///
43         void draw(PainterInfo & pi, int x, int y) const;
44         ///
45         virtual DisplayType display() const;
46
47         /// get the parameters
48         InsetCommandParams const & params() const;
49
50         ///
51         Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
52         /** Fills \c list
53          *  \param buffer the Buffer containing this inset.
54          *  \param list the list of labels in the child buffer.
55          */
56         void getLabelList(Buffer const & buffer,
57                           std::vector<docstring> & list) const;
58         /** Fills \c keys
59          *  \param buffer the Buffer containing this inset.
60          *  \param keys the list of bibkeys in the child buffer.
61          */
62         void fillWithBibKeys(Buffer const & buffer,
63                 std::vector<std::pair<std::string, docstring> > & keys) const;
64         /** Update the cache with all bibfiles in use of the child buffer
65          *  (including bibfiles of grandchild documents).
66          *  Does nothing if the child document is not loaded to prevent
67          *  automatic loading of all child documents upon loading the master.
68          *  \param buffer the Buffer containing this inset.
69          */
70         void updateBibfilesCache(Buffer const & buffer);
71         /** Return the cache with all bibfiles in use of the child buffer
72          *  (including bibfiles of grandchild documents).
73          *  Return an empty vector if the child doc is not loaded.
74          *  \param buffer the Buffer containing this inset.
75          */
76         std::vector<support::FileName> const &
77         getBibfilesCache(Buffer const & buffer) const;
78         ///
79         EDITABLE editable() const { return IS_EDITABLE; }
80         ///
81         void write(Buffer const &, std::ostream &) const;
82         ///
83         void read(Buffer const &, Lexer &);
84         ///
85         int latex(Buffer const &, odocstream &,
86                   OutputParams const &) const;
87         ///
88         int plaintext(Buffer const &, odocstream &,
89                       OutputParams const &) const;
90         ///
91         int docbook(Buffer const &, odocstream &,
92                     OutputParams const &) const;
93         ///
94         void validate(LaTeXFeatures &) const;
95         ///
96         void addPreview(graphics::PreviewLoader &) const;
97         ///
98         void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
99         ///
100         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
101         ///
102         void updateLabels(Buffer const & buffer, ParIterator const &) const;
103 protected:
104         InsetInclude(InsetInclude const &);
105         ///
106         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
107 private:
108         virtual std::auto_ptr<Inset> doClone() const;
109
110         /** Slot receiving a signal that the external file has changed
111          *  and the preview should be regenerated.
112          */
113         void fileChanged() const;
114
115         friend class InsetIncludeMailer;
116
117         /// set the parameters
118         void set(InsetCommandParams const & params, Buffer const &);
119         /// get the text displayed on the button
120         docstring const getScreenLabel(Buffer const &) const;
121         ///
122         void write(std::ostream &) const;
123         ///
124         void read(Lexer &);
125
126         /// the parameters
127         InsetCommandParams params_;
128         /// holds the entity name that defines the file location (SGML)
129         docstring const include_label;
130
131         /// The pointer never changes although *preview_'s contents may.
132         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
133
134         /// cache
135         mutable bool set_label_;
136         mutable RenderButton button_;
137         mutable docstring listings_label_;
138 };
139
140
141 class InsetIncludeMailer : public MailInset {
142 public:
143         ///
144         InsetIncludeMailer(InsetInclude & inset);
145         ///
146         virtual Inset & inset() const { return inset_; }
147         ///
148         virtual std::string const & name() const { return name_; }
149         ///
150         virtual std::string const inset2string(Buffer const &) const;
151         ///
152         static void string2params(std::string const &, InsetCommandParams &);
153         ///
154         static std::string const params2string(InsetCommandParams const &);
155 private:
156         ///
157         static std::string const name_;
158         ///
159         InsetInclude & inset_;
160 };
161
162 /// return loaded Buffer or zero if the file loading did not proceed.
163 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
164
165 } // namespace lyx
166
167 #endif // INSETINCLUDE_H