]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
parlist-a-1.diff
[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 &) 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         /// take up a whole row if we're not type INPUT
111         bool display() const;
112
113         /// return true if the file is or got loaded.
114         bool loadIfNeeded() const;
115
116         ///
117         void addPreview(grfx::PreviewLoader &) const;
118
119 private:
120         /// get the text displayed on the button
121         string const getScreenLabel(Buffer const *) const;
122         /// is this a verbatim include ?
123         bool isVerbatim() const;
124         /// get the filename of the master buffer
125         string const getMasterFilename() const;
126         /// get the included file name
127         string const getFileName() const;
128
129         /// the parameters
130         Params params_;
131         /// holds the entity name that defines the file location (SGML)
132         string const include_label;
133
134         /// Use the Pimpl idiom to hide the internals of the previewer.
135         class PreviewImpl;
136         friend class PreviewImpl;
137         /// The pointer never changes although *preview_'s contents may.
138         boost::scoped_ptr<PreviewImpl> const preview_;
139 };
140
141
142 inline bool InsetInclude::isVerbatim() const
143 {
144         return params_.flag == VERB || params_.flag == VERBAST;
145 }
146
147 #include "mailinset.h"
148
149 class InsetIncludeMailer : public MailInset {
150 public:
151         ///
152         InsetIncludeMailer(InsetInclude & inset);
153         ///
154         virtual InsetBase & inset() const { return inset_; }
155         ///
156         virtual string const & name() const { return name_; }
157         ///
158         virtual string const inset2string() const;
159         ///
160         static void string2params(string const &, InsetInclude::Params &);
161         ///
162         static string const params2string(InsetInclude::Params const &);
163 private:
164         ///
165         static string const name_;
166         ///
167         InsetInclude & inset_;
168 };
169
170 #endif // INSETINCLUDE_H