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