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