]> git.lyx.org Git - features.git/blob - src/insets/InsetInclude.h
Move the lyx::biblio namespace into src/. Also make changes to how the BibTeX
[features.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         virtual void fillWithBibKeys(Buffer const &,
63                 std::vector<std::pair<std::string, docstring> > &,
64                 InsetIterator const & /*di*/) const;
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         std::vector<support::FileName> const &
78         getBibfilesCache(Buffer const & buffer) const;
79         ///
80         EDITABLE editable() const { return IS_EDITABLE; }
81         ///
82         void write(Buffer const &, std::ostream &) const;
83         ///
84         void read(Buffer const &, Lexer &);
85         ///
86         int latex(Buffer const &, odocstream &,
87                   OutputParams const &) const;
88         ///
89         int plaintext(Buffer const &, odocstream &,
90                       OutputParams const &) const;
91         ///
92         int docbook(Buffer const &, odocstream &,
93                     OutputParams const &) const;
94         ///
95         void validate(LaTeXFeatures &) const;
96         ///
97         void addPreview(graphics::PreviewLoader &) const;
98         ///
99         void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
100         ///
101         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
102         ///
103         void updateLabels(Buffer const & buffer, ParIterator const &) const;
104 protected:
105         InsetInclude(InsetInclude const &);
106         ///
107         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
108 private:
109         virtual std::auto_ptr<Inset> doClone() 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         friend class InsetIncludeMailer;
117
118         /// set the parameters
119         void set(InsetCommandParams const & params, Buffer const &);
120         /// get the text displayed on the button
121         docstring const getScreenLabel(Buffer const &) const;
122         ///
123         void write(std::ostream &) const;
124         ///
125         void read(Lexer &);
126
127         /// the parameters
128         InsetCommandParams params_;
129         /// holds the entity name that defines the file location (SGML)
130         docstring const include_label;
131
132         /// The pointer never changes although *preview_'s contents may.
133         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
134
135         /// cache
136         mutable bool set_label_;
137         mutable RenderButton button_;
138         mutable docstring listings_label_;
139 };
140
141
142 class InsetIncludeMailer : public MailInset {
143 public:
144         ///
145         InsetIncludeMailer(InsetInclude & inset);
146         ///
147         virtual Inset & inset() const { return inset_; }
148         ///
149         virtual std::string const & name() const { return name_; }
150         ///
151         virtual std::string const inset2string(Buffer const &) const;
152         ///
153         static void string2params(std::string const &, InsetCommandParams &);
154         ///
155         static std::string const params2string(InsetCommandParams const &);
156 private:
157         ///
158         static std::string const name_;
159         ///
160         InsetInclude & inset_;
161 };
162
163 /// return loaded Buffer or zero if the file loading did not proceed.
164 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
165
166 } // namespace lyx
167
168 #endif // INSETINCLUDE_H