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