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