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