]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
8a57c739fbd0e09cccb3fe75269ea0a792b6594c
[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
16 #include "insetcommand.h"
17
18 #include <boost/scoped_ptr.hpp>
19
20 class Buffer;
21 struct LaTeXFeatures;
22
23 // Created by AAS 970521
24
25 /// for including tex/lyx files
26 class InsetInclude: public InsetButton, boost::noncopyable {
27 public:
28         /// the type of inclusion
29         enum Flags {
30                 INCLUDE = 0, //<
31                 VERB = 1, //<
32                 INPUT = 2, //<
33                 VERBAST = 3 //<
34         };
35
36         struct Params {
37                 Params(InsetCommandParams const & cp = InsetCommandParams("input"),
38                        Flags f = INPUT,
39                        string const & name = string())
40                         : cparams(cp), flag(f),
41                           masterFilename_(name) {}
42
43                 InsetCommandParams cparams;
44                 Flags flag;
45                 string masterFilename_;
46
47                 ///
48                 bool operator==(Params const &) const;
49                 ///
50                 bool operator!=(Params const &) const;
51         };
52
53         ///
54         InsetInclude(Params const &);
55         ///
56         InsetInclude(InsetCommandParams const &, Buffer const &);
57
58         ~InsetInclude();
59
60         ///
61         virtual dispatch_result localDispatch(FuncRequest const & cmd); 
62
63         /// Override these InsetButton methods if Previewing
64         int ascent(BufferView *, LyXFont const &) const;
65         ///
66         int descent(BufferView *, LyXFont const &) const;
67         ///
68         int width(BufferView *, LyXFont const &) const;
69         ///
70         void draw(BufferView *, LyXFont const &, int, float &, bool) const;
71
72         /// get the parameters
73         Params const & params(void) const;
74         /// set the parameters
75         void set(Params const & params);
76
77         ///
78         virtual Inset * clone(Buffer const &, bool same_id = false) const;
79         ///
80         Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
81         /// This returns the list of labels on the child buffer
82         std::vector<string> const getLabelList() const;
83         /// This returns the list of bibkeys on the child buffer
84         void fillWithBibKeys(std::vector<std::pair<string,string> > & keys) const;
85         ///
86         void edit(BufferView *, int x, int y, mouse_button::state button);
87         ///
88         void edit(BufferView * bv, bool front = true);
89         ///
90         EDITABLE editable() const
91         {
92                 return IS_EDITABLE;
93         }
94         /// With lyx3 we won't overload these 3 methods
95         void write(Buffer const *, std::ostream &) const;
96         ///
97         void read(Buffer const *, LyXLex &);
98         ///
99         int latex(Buffer const *, std::ostream &,
100                   bool fragile, bool free_spc) const;
101         ///
102         int ascii(Buffer const *, std::ostream &, int linelen) const;
103         ///
104         int linuxdoc(Buffer const *, std::ostream &) const;
105         ///
106         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
107         ///
108         void validate(LaTeXFeatures &) const;
109
110         /** Input inserts anything inside a paragraph.
111             Display can give some visual feedback
112         */
113         bool display() const;
114
115         /// return the filename stub of the included file
116         string const getRelFileBaseName() const;
117
118         /// return true if the file is or got loaded.
119         bool loadIfNeeded() const;
120
121         ///
122         void addPreview(grfx::PreviewLoader &) const;
123
124 private:
125         /// get the text displayed on the button
126         string const getScreenLabel(Buffer const *) const;
127         /// is this a verbatim include ?
128         bool isVerbatim() const;
129         /// get the filename of the master buffer
130         string const getMasterFilename() const;
131         /// get the included file name
132         string const getFileName() const;
133
134         /// the parameters
135         Params params_;
136         /// holds the entity name that defines the file location (SGML)
137         string const include_label;
138
139         /// Use the Pimpl idiom to hide the internals of the previewer.
140         class PreviewImpl;
141         friend class PreviewImpl;
142         /// The pointer never changes although *preview_'s contents may.
143         boost::scoped_ptr<PreviewImpl> const preview_;
144 };
145
146
147 inline bool InsetInclude::isVerbatim() const
148 {
149         return params_.flag == VERB || params_.flag == VERBAST;
150 }
151
152 #include "mailinset.h"
153
154 class InsetIncludeMailer : public MailInset {
155 public:
156         ///
157         InsetIncludeMailer(InsetInclude & inset);
158         ///
159         virtual Inset & inset() const { return inset_; }
160         ///
161         virtual string const & name() const { return name_; }
162         ///
163         virtual string const inset2string() const;
164         ///
165         static void string2params(string const &, InsetInclude::Params &);
166         ///
167         static string const params2string(InsetInclude::Params const &);
168 private:
169         ///
170         static string const name_;
171         ///
172         InsetInclude & inset_;
173 };
174
175 #endif // INSETINCLUDE_H