]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
Enable convertDefault.sh to run even if its executable bit is not set.
[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 #include "dimension.h"
17 #include "renderers.h"
18 #include <boost/scoped_ptr.hpp>
19
20
21 class Buffer;
22 struct LaTeXFeatures;
23
24 // Created by AAS 970521
25
26 /// for including tex/lyx files
27 class InsetInclude: public InsetOld {
28 public:
29         /// the type of inclusion
30         enum Flags {
31                 INCLUDE = 0, //<
32                 VERB = 1, //<
33                 INPUT = 2, //<
34                 VERBAST = 3 //<
35         };
36
37         struct Params {
38                 Params(InsetCommandParams const & cp = InsetCommandParams("input"),
39                        Flags f = INPUT,
40                        string const & name = string())
41                         : cparams(cp), flag(f),
42                           masterFilename_(name) {}
43
44                 InsetCommandParams cparams;
45                 Flags flag;
46                 string masterFilename_;
47
48                 ///
49                 bool operator==(Params const &) const;
50                 ///
51                 bool operator!=(Params const &) const;
52         };
53
54         ///
55         InsetInclude(Params const &);
56         InsetInclude(InsetCommandParams const &, Buffer const &);
57         InsetInclude(InsetInclude const &);
58
59         ~InsetInclude();
60
61         ///
62         virtual dispatch_result localDispatch(FuncRequest const & cmd);
63
64         /// Override these InsetButton methods if Previewing
65         void metrics(MetricsInfo & mi, Dimension & dim) const;
66         ///
67         void draw(PainterInfo & pi, int x, int y) const;
68         ///
69         virtual BufferView * view() 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 std::auto_ptr<InsetBase> clone() const;
78         ///
79         InsetOld::Code lyxCode() const { return InsetOld::INCLUDE_CODE; }
80         /// This returns the list of labels on the child buffer
81         void getLabelList(std::vector<string> &) 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         ///
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         /// return true if the file is or got loaded.
106         bool loadIfNeeded() const;
107
108         ///
109         void addPreview(lyx::graphics::PreviewLoader &) const;
110
111 private:
112         friend class InsetIncludeMailer;
113         
114         ///
115         void write(std::ostream &) const;
116         ///
117         void read(LyXLex &);
118         /// get the text displayed on the button
119         string const getScreenLabel(Buffer const &) const;
120         /// is this a verbatim include ?
121         bool isVerbatim() const;
122         /// get the filename of the master buffer
123         string const getMasterFilename() const;
124         /// get the included file name
125         string const getFileName() const;
126
127         /// the parameters
128         Params params_;
129         /// holds the entity name that defines the file location (SGML)
130         string const include_label;
131
132         /// Use the Pimpl idiom to hide the internals of the previewer.
133         class PreviewImpl;
134         friend class PreviewImpl;
135         /// The pointer never changes although *preview_'s contents may.
136         boost::scoped_ptr<PreviewImpl> const preview_;
137
138         /// cache
139         mutable bool set_label_;
140         mutable ButtonRenderer button_;
141         mutable unsigned int center_indent_;
142 };
143
144
145 inline bool InsetInclude::isVerbatim() const
146 {
147         return params_.flag == VERB || params_.flag == VERBAST;
148 }
149
150 #include "mailinset.h"
151
152 class InsetIncludeMailer : public MailInset {
153 public:
154         ///
155         InsetIncludeMailer(InsetInclude & inset);
156         ///
157         virtual InsetBase & inset() const { return inset_; }
158         ///
159         virtual string const & name() const { return name_; }
160         ///
161         virtual string const inset2string(Buffer const &) const;
162         ///
163         static void string2params(string const &, InsetInclude::Params &);
164         ///
165         static string const params2string(InsetInclude::Params const &);
166 private:
167         ///
168         static string const name_;
169         ///
170         InsetInclude & inset_;
171 };
172
173 #endif // INSETINCLUDE_H