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