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