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