]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
* the old cursor is stored before dispatch and then used after moving
[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;
99         ///
100         void updateLabels(Buffer const & buffer) const;
101         ///
102         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
103         /// if this inset contains lstinputlisting and has a caption,
104         /// update internal counter and passed counter
105         void updateCounter(Counters & counters);
106 protected:
107         InsetInclude(InsetInclude const &);
108         ///
109         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
110 private:
111         virtual std::auto_ptr<Inset> doClone() const;
112
113         /** Slot receiving a signal that the external file has changed
114          *  and the preview should be regenerated.
115          */
116         void fileChanged() const;
117
118         friend class InsetIncludeMailer;
119
120         /// set the parameters
121         void set(InsetCommandParams const & params, Buffer const &);
122         /// get the text displayed on the button
123         docstring const getScreenLabel(Buffer const &) const;
124         ///
125         void write(std::ostream &) const;
126         ///
127         void read(Lexer &);
128
129         /// the parameters
130         InsetCommandParams params_;
131         /// holds the entity name that defines the file location (SGML)
132         docstring const include_label;
133
134         /// The pointer never changes although *preview_'s contents may.
135         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
136
137         /// cache
138         mutable bool set_label_;
139         mutable RenderButton button_;
140         int counter_;
141 };
142
143
144 class InsetIncludeMailer : public MailInset {
145 public:
146         ///
147         InsetIncludeMailer(InsetInclude & inset);
148         ///
149         virtual Inset & inset() const { return inset_; }
150         ///
151         virtual std::string const & name() const { return name_; }
152         ///
153         virtual std::string const inset2string(Buffer const &) const;
154         ///
155         static void string2params(std::string const &, InsetCommandParams &);
156         ///
157         static std::string const params2string(InsetCommandParams const &);
158 private:
159         ///
160         static std::string const name_;
161         ///
162         InsetInclude & inset_;
163 };
164
165
166 } // namespace lyx
167
168 #endif // INSETINCLUDE_H