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