]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
* dimension.h: new operator!=() and operator=()
[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 "render_button.h"
18 #include "mailinset.h"
19
20 #include <boost/scoped_ptr.hpp>
21
22 namespace lyx {
23
24 class Buffer;
25 class Dimension;
26 class LaTeXFeatures;
27 class RenderMonitoredPreview;
28
29
30 /// for including tex/lyx files
31 class InsetInclude : public InsetOld {
32 public:
33         ///
34         InsetInclude(InsetCommandParams const &);
35         ~InsetInclude();
36
37         /// Override these InsetButton methods if Previewing
38         bool metrics(MetricsInfo & mi, Dimension & dim) const;
39         ///
40         void draw(PainterInfo & pi, int x, int y) const;
41         ///
42         virtual bool display() const;
43
44         /// get the parameters
45         InsetCommandParams const & params() const;
46
47         ///
48         InsetBase::Code lyxCode() const { return InsetBase::INCLUDE_CODE; }
49         /** Fills \c list
50          *  \param buffer the Buffer containing this inset.
51          *  \param list the list of labels in the child buffer.
52          */
53         void getLabelList(Buffer const & buffer,
54                           std::vector<docstring> & list) const;
55         /** Fills \c keys
56          *  \param buffer the Buffer containing this inset.
57          *  \param keys the list of bibkeys in the child buffer.
58          */
59         void fillWithBibKeys(Buffer const & buffer,
60                 std::vector<std::pair<std::string,std::string> > & keys) const;
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         std::vector<std::string> const &
74         getBibfilesCache(Buffer const & buffer) const;
75         ///
76         EDITABLE editable() const { return IS_EDITABLE; }
77         ///
78         void write(Buffer const &, std::ostream &) const;
79         ///
80         void read(Buffer const &, LyXLex &);
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 &) const;
96         ///
97         void updateLabels(Buffer const & buffer) const;
98         ///
99         bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
100 protected:
101         InsetInclude(InsetInclude const &);
102         ///
103         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
104 private:
105         virtual std::auto_ptr<InsetBase> doClone() const;
106
107         /** Slot receiving a signal that the external file has changed
108          *  and the preview should be regenerated.
109          */
110         void fileChanged() const;
111
112         friend class InsetIncludeMailer;
113
114         /// set the parameters
115         void set(InsetCommandParams const & params, Buffer const &);
116         /// get the text displayed on the button
117         docstring const getScreenLabel(Buffer const &) const;
118         ///
119         void write(std::ostream &) const;
120         ///
121         void read(LyXLex &);
122
123         /// the parameters
124         InsetCommandParams params_;
125         /// holds the entity name that defines the file location (SGML)
126         docstring const include_label;
127
128         /// The pointer never changes although *preview_'s contents may.
129         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
130
131         /// cache
132         mutable bool set_label_;
133         mutable RenderButton button_;
134 };
135
136
137 class InsetIncludeMailer : public MailInset {
138 public:
139         ///
140         InsetIncludeMailer(InsetInclude & inset);
141         ///
142         virtual InsetBase & inset() const { return inset_; }
143         ///
144         virtual std::string const & name() const { return name_; }
145         ///
146         virtual std::string const inset2string(Buffer const &) const;
147         ///
148         static void string2params(std::string const &, InsetCommandParams &);
149         ///
150         static std::string const params2string(InsetCommandParams const &);
151 private:
152         ///
153         static std::string const name_;
154         ///
155         InsetInclude & inset_;
156 };
157
158
159 } // namespace lyx
160
161 #endif // INSETINCLUDE_H