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