]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
5e96daea3211a7b16cb7b38ded1a3cb085a8e482
[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 <boost/scoped_ptr.hpp>
19
20 class Buffer;
21 class Dimension;
22 struct LaTeXFeatures;
23 class RenderMonitoredPreview;
24
25
26 /// for including tex/lyx files
27 class InsetInclude: public InsetOld {
28 public:
29         ///
30         InsetInclude(InsetCommandParams const &);
31         InsetInclude(InsetInclude const &);
32         ~InsetInclude();
33
34         ///
35         virtual std::auto_ptr<InsetBase> clone() const;
36
37         ///
38         virtual dispatch_result localDispatch(FuncRequest const & cmd);
39
40         /// Override these InsetButton methods if Previewing
41         void metrics(MetricsInfo & mi, Dimension & dim) const;
42         ///
43         void draw(PainterInfo & pi, int x, int y) const;
44
45         /// get the parameters
46         InsetCommandParams const & params(void) const;
47
48         ///
49         InsetOld::Code lyxCode() const { return InsetOld::INCLUDE_CODE; }
50         /** Fills \c list
51          *  \param buffer the Buffer containing this inset.
52          *  \param list the list of labels in the child buffer.
53          */
54         void getLabelList(Buffer const & buffer,
55                           std::vector<std::string> & list) const;
56         /** Fills \c keys
57          *  \param buffer the Buffer containing this inset.
58          *  \param keys the list of bibkeys in the child buffer.
59          */
60         ///
61         void fillWithBibKeys(Buffer const & buffer,
62                 std::vector<std::pair<std::string,std::string> > & keys) const;
63         ///
64         EDITABLE editable() const { return IS_EDITABLE; }
65         ///
66         void write(Buffer const &, std::ostream &) const;
67         ///
68         void read(Buffer const &, LyXLex &);
69         ///
70         int latex(Buffer const &, std::ostream &, LatexRunParams const &) const;
71         ///
72         int ascii(Buffer const &, std::ostream &, int linelen) const;
73         ///
74         int linuxdoc(Buffer const &, std::ostream &) const;
75         ///
76         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
77         ///
78         void validate(LaTeXFeatures &) const;
79         ///
80         void addPreview(lyx::graphics::PreviewLoader &) const;
81
82 private:
83         /// Slot receiving a signal that the preview is ready to display.
84         void statusChanged() const;
85         /** Slot receiving a signal that the external file has changed
86          *  and the preview should be regenerated.
87          */
88         void fileChanged() const;
89
90         friend class InsetIncludeMailer;
91
92         /// set the parameters
93         void set(InsetCommandParams const & params, Buffer const &);
94         /// get the text displayed on the button
95         std::string const getScreenLabel(Buffer const &) const;
96         ///
97         void write(std::ostream &) const;
98         ///
99         void read(LyXLex &);
100
101         /// the parameters
102         InsetCommandParams params_;
103         /// holds the entity name that defines the file location (SGML)
104         std::string const include_label;
105
106         /// The pointer never changes although *preview_'s contents may.
107         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
108
109         /// cache
110         mutable bool set_label_;
111         mutable RenderButton button_;
112 };
113
114
115 #include "mailinset.h"
116
117 class InsetIncludeMailer : public MailInset {
118 public:
119         ///
120         InsetIncludeMailer(InsetInclude & inset);
121         ///
122         virtual InsetBase & inset() const { return inset_; }
123         ///
124         virtual std::string const & name() const { return name_; }
125         ///
126         virtual std::string const inset2string(Buffer const &) const;
127         ///
128         static void string2params(std::string const &, InsetCommandParams &);
129         ///
130         static std::string const params2string(InsetCommandParams const &);
131 private:
132         ///
133         static std::string const name_;
134         ///
135         InsetInclude & inset_;
136 };
137
138 #endif // INSETINCLUDE_H