]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
5dc86d56fc3b409169b62d72aa4d409a1f1573e3
[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 #include "buffer.h"
20 #include "support/filetools.h"
21
22 struct LaTeXFeatures;
23
24 // Created by AAS 970521
25
26 /**  Used to include files
27  */
28 class InsetInclude: public InsetCommand {
29 public:
30         ///
31         InsetInclude(): InsetCommand("include")
32         {
33                 flag = InsetInclude::INCLUDE;
34         }
35         ///
36         InsetInclude(string const &,  Buffer *);
37         ///
38         ~InsetInclude();
39         ///
40         Inset * Clone() const;
41         ///
42         Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; }
43         /// This returns the list of labels on the child buffer
44         std::vector<string> getLabelList() const;
45         /// This returns the list of bibkeys on the child buffer
46         std::vector< std::pair<string,string> > getKeys() const;
47         ///
48         void Edit(BufferView *, int x, int y, unsigned int button);
49         ///
50         EDITABLE Editable() const
51         {
52                 return IS_EDITABLE;
53         }
54         /// With lyx3 we won't overload these 3 methods
55         void Write(Buffer const *, std::ostream &) const;
56         ///
57         void Read(Buffer const *, LyXLex &);
58         /// 
59         int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
60         ///
61         int Linuxdoc(Buffer const *, std::ostream &) const;
62         ///
63         int DocBook(Buffer const *, std::ostream &) const;
64         ///
65         void Validate(LaTeXFeatures &) const;
66         
67         /// Input inserts anything inside a paragraph, Display can give some visual feedback 
68         bool display() const;
69         ///
70         string getScreenLabel() const;
71         ///
72         void setContents(string const & c);
73         ///
74         void setFilename(string const & n) { setContents(n); }
75         ///
76         string getMasterFilename() const { return master->fileName(); }
77         ///
78         string getFileName() const { 
79                 return filename;
80         }
81         ///  In "input" mode uses \input instead of \include.
82         bool isInput() const { return flag == InsetInclude::INPUT; }
83         ///  If this is true, the child file shouldn't be loaded by lyx
84         bool isNoLoad() const { return noload; }
85
86         /**  A verbatim file shouldn't be loaded by LyX
87          *  No need to generate LaTeX code of a verbatim file
88          */ 
89         bool isVerb() const;
90         ///
91         bool isVerbVisibleSpace() const { return flag == InsetInclude::VERBAST;}
92         ///  
93         bool isInclude() const { return flag == InsetInclude::INCLUDE;}
94         ///  
95         void setInput();
96         ///  
97         void setNoLoad(bool);
98         ///  
99         void setInclude();
100         ///  
101         void setVerb();
102         ///
103         void setVisibleSpace(bool b);
104         /// return true if the file is or got loaded.
105         bool loadIfNeeded() const;
106 private:
107         ///
108         enum Include_Flags {
109                 ///
110                 INCLUDE= 0,
111                 ///
112                 VERB = 1,
113                 ///
114                 INPUT = 2,
115                 ///
116                 VERBAST = 3
117         };
118         
119         ///
120         bool noload;
121         ///
122         int flag;
123         ///
124         Buffer * master;
125         ///
126         string filename;
127         ///
128         mutable string include_label;
129 };
130
131
132 inline 
133 bool InsetInclude::isVerb() const
134 {
135         return flag == InsetInclude::VERB || flag == InsetInclude::VERBAST; 
136 }
137
138
139 inline
140 void InsetInclude::setInput()
141 {
142         if (!isInput()) {
143             flag = InsetInclude::INPUT;
144             setCmdName("input");
145         }
146 }
147
148
149 inline
150 void InsetInclude::setNoLoad(bool b)
151
152                 noload = b;
153 }
154
155
156 inline
157 void InsetInclude::setInclude()
158 {
159         if (!isInclude()) {
160             flag = InsetInclude::INCLUDE;
161             setCmdName("include");
162         }
163 }
164
165
166 inline
167 void InsetInclude::setVerb()
168
169         if (!isVerb()) {
170             flag = InsetInclude::VERB;
171             setCmdName("verbatiminput");
172         }
173 }
174
175
176 inline
177 void InsetInclude::setVisibleSpace(bool b)
178 {
179         if (b && flag == InsetInclude::VERB) {
180             setCmdName("verbatiminput*");
181             flag = InsetInclude::VERBAST;
182         } else if (!b && flag == InsetInclude::VERBAST) {
183             setCmdName("verbatiminput");
184             flag = InsetInclude::VERB;
185         }
186 }
187 #endif