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