]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
7ea9085fa0eeca45bc7792bd87d37e7323d4d16d
[lyx.git] / src / insets / insetinclude.h
1 // -*- C++ -*-
2 /* This file is part of*
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *       
7  *          Copyright (C) 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 is 1 if the childs have labels, 0 otherwise
44         int GetNumberOfLabels() const;
45         /// This returns the list of labels on the child buffer
46         string getLabel(int) const;
47         /// This returns the list of bibkeys on the child buffer
48         string getKeys(char delim) const;
49         ///
50         void Edit(BufferView *, int x, int y, unsigned int button);
51         ///
52         unsigned char Editable() const
53         {
54                 return 1;
55         }
56         /// With lyx3 we won't overload these 3 methods
57         void Write(ostream &) const;
58         ///
59         void Read(LyXLex &);
60         /// 
61         int Latex(ostream &, signed char fragile) const;
62 #ifndef USE_OSTREAM_ONLY
63         ///
64         int Latex(string & file, signed char fragile) const;
65 #endif
66         ///
67         void Validate(LaTeXFeatures &) const;
68         
69         /// Input inserts anything inside a paragraph, Display can give some visual feedback 
70         bool display() const { return !(isInput()); }
71         ///
72         string getScreenLabel() const;
73         ///
74         void setContents(string const & c) {
75                 InsetCommand::setContents(c);
76                 filename = MakeAbsPath(contents, 
77                                        OnlyPath(getMasterFilename())); 
78         }
79         ///
80         void setFilename(string const & n) { setContents(n); }
81         ///
82         string getMasterFilename() const { return master->fileName(); }
83         ///
84         string getFileName() const { 
85                 return filename;
86         }
87         ///  In "input" mode uses \input instead of \include.
88         bool isInput() const { return flag == InsetInclude::INPUT; }
89         ///  If this is true, the child file shouldn't be loaded by lyx
90         bool isNoLoad() const { return noload; }
91
92         /**  A verbatim file shouldn't be loaded by LyX
93          *  No need to generate LaTeX code of a verbatim file
94          */ 
95         bool isVerb() const;
96         ///
97         bool isVerbVisibleSpace() const { return flag == InsetInclude::VERBAST;}
98         ///  
99         bool isInclude() const { return flag == InsetInclude::INCLUDE;}
100         ///  
101         void setInput();
102         ///  
103         void setNoLoad(bool);
104         ///  
105         void setInclude();
106         ///  
107         void setVerb();
108         ///
109         void setVisibleSpace(bool b);
110         /// return true if the file is or got loaded.
111         bool loadIfNeeded() const;
112 private:
113         ///
114         enum Include_Flags {
115                 ///
116                 INCLUDE= 0,
117                 ///
118                 VERB = 1,
119                 ///
120                 INPUT = 2,
121                 ///
122                 VERBAST = 3
123         };
124         
125         ///
126         bool noload;
127         ///
128         int flag;
129         ///
130         Buffer * master;
131         ///
132         string filename;
133 };
134
135
136 inline 
137 bool InsetInclude::isVerb() const
138 {
139         return flag == InsetInclude::VERB || flag == InsetInclude::VERBAST; 
140 }
141
142
143 inline
144 void InsetInclude::setInput()
145 {
146         if (!isInput()) {
147             flag = InsetInclude::INPUT;
148             setCmdName("input");
149         }
150 }
151
152
153 inline
154 void InsetInclude::setNoLoad(bool b)
155
156                 noload = b;
157 }
158
159
160 inline
161 void InsetInclude::setInclude()
162 {
163         if (!isInclude()) {
164             flag = InsetInclude::INCLUDE;
165             setCmdName("include");
166         }
167 }
168
169
170 inline
171 void InsetInclude::setVerb()
172
173         if (!isVerb()) {
174             flag = InsetInclude::VERB;
175             setCmdName("verbatiminput");
176         }
177 }
178
179
180 inline
181 void InsetInclude::setVisibleSpace(bool b)
182 {
183         if (b && flag == InsetInclude::VERB) {
184             setCmdName("verbatiminput*");
185             flag = InsetInclude::VERBAST;
186         } else if (!b && flag == InsetInclude::VERBAST) {
187             setCmdName("verbatiminput");
188             flag = InsetInclude::VERB;
189         }
190 }
191 #endif