]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
Angus insetindex patch + protect patch from Dekel
[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
20 class Buffer;
21 struct LaTeXFeatures;
22
23 // Created by AAS 970521
24
25 /**  Used to include files
26  */
27 class InsetInclude: public InsetCommand {
28 public:
29 #if 0
30         ///
31         InsetInclude(): InsetCommand("include")
32         {
33                 flag = InsetInclude::INCLUDE;
34         }
35 #endif
36         ///
37         InsetInclude(string const &,  Buffer *);
38         ///
39         ~InsetInclude();
40         ///
41         Inset * Clone() const;
42         ///
43         Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; }
44         /// This returns the list of labels on the child buffer
45         std::vector<string> getLabelList() const;
46         /// This returns the list of bibkeys on the child buffer
47         std::vector< std::pair<string,string> > getKeys() const;
48         ///
49         void Edit(BufferView *, int x, int y, unsigned int button);
50         ///
51         EDITABLE Editable() const
52         {
53                 return IS_EDITABLE;
54         }
55         /// With lyx3 we won't overload these 3 methods
56         void Write(Buffer const *, std::ostream &) const;
57         ///
58         void Read(Buffer const *, LyXLex &);
59         /// 
60         int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
61         ///
62         int Linuxdoc(Buffer const *, std::ostream &) const;
63         ///
64         int DocBook(Buffer const *, std::ostream &) const;
65         ///
66         void Validate(LaTeXFeatures &) const;
67         
68         /** Input inserts anything inside a paragraph.
69             Display can give some visual feedback
70         */
71         bool display() const;
72         ///
73         string getScreenLabel() const;
74         ///
75         string getMasterFilename() const;
76         ///
77         string getFileName() const;
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 {
90                 return flag == InsetInclude::VERBAST;
91         }
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         mutable string include_label;
127 };
128
129
130 inline 
131 bool InsetInclude::isVerb() const
132 {
133         return flag == InsetInclude::VERB || flag == InsetInclude::VERBAST; 
134 }
135
136
137 inline
138 void InsetInclude::setInput()
139 {
140         if (!isInput()) {
141             flag = InsetInclude::INPUT;
142             setCmdName("input");
143         }
144 }
145
146
147 inline
148 void InsetInclude::setNoLoad(bool b)
149
150                 noload = b;
151 }
152
153
154 inline
155 void InsetInclude::setInclude()
156 {
157         if (!isInclude()) {
158             flag = InsetInclude::INCLUDE;
159             setCmdName("include");
160         }
161 }
162
163
164 inline
165 void InsetInclude::setVerb()
166
167         if (!isVerb()) {
168             flag = InsetInclude::VERB;
169             setCmdName("verbatiminput");
170         }
171 }
172
173
174 inline
175 void InsetInclude::setVisibleSpace(bool b)
176 {
177         if (b && flag == InsetInclude::VERB) {
178             setCmdName("verbatiminput*");
179             flag = InsetInclude::VERBAST;
180         } else if (!b && flag == InsetInclude::VERBAST) {
181             setCmdName("verbatiminput");
182             flag = InsetInclude::VERB;
183         }
184 }
185 #endif