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