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