]> git.lyx.org Git - features.git/blob - src/buffer.h
New dutch example files; the usual set of dec cxx fixes.
[features.git] / src / buffer.h
1 // -*- C++ -*-
2 /* This file is part of
3 * ====================================================== 
4
5 *           LyX, The Document Processor          
6 *           Copyright (C) 1995 Matthias Ettrich
7 *
8 *           This file is Copyleft (C) 1996
9 *           Lars Gullik Bjønnes
10 *
11 * ====================================================== */
12  
13 // Change Log:
14 // =========== 
15 // 23/03/98   Heinrich Bauer (heinrich.bauer@t-mobil.de)
16 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
17 // following bug: dvi file export did not work after printing (or previewing)
18 // and vice versa as long as the same file was concerned. This happened
19 // every time the LyX-file was left unchanged between the two actions mentioned
20 // above.
21
22 #ifndef BUFFER_H
23 #define BUFFER_H
24
25 #ifdef __GNUG__
26 #pragma interface
27 #endif
28
29 #include "undo.h"
30 #include "BufferView.h"
31 #include "lyxvc.h"
32 #include "bufferparams.h"
33 #include "texrow.h"
34 #include "lyxtext.h"
35 #include "support/filetools.h"
36
37
38 class LyXRC;
39 class TeXErrors;
40 class LaTeXFeatures;
41
42 extern void updateAllVisibleBufferRelatedPopups();
43 extern void WarnReadonly();
44
45 ///
46 struct DEPCLEAN {
47         ///
48         bool clean;
49         ///
50         string master;
51         ///
52         DEPCLEAN *next;
53 };
54
55 /** The buffer object.
56   The is is the buffer object. It contains all the informations about
57   a document loaded into LyX. I am not sure if the class is complete or
58   minimal, probably not.
59   */
60 class Buffer {
61 public:
62         /**@name Constructors and destructor */
63         //@{
64         ///
65         Buffer(string const & file, LyXRC * lyxrc = 0, bool b = false);
66         
67         ///
68         ~Buffer();
69         //@}
70
71         /**@name Methods */
72         //@{
73
74         /** save the buffer's parameters as user default
75           This function saves a file user_lyxdir/templates/defaults.lyx 
76           which parameters are those of the current buffer. This file
77           is used as a default template when creating a new
78           file. Returns true on success.
79           */
80         bool saveParamsAsDefaults();
81
82         /// should be changed to work for a list.
83         void resize()
84         {
85                 if (users) {
86                         users->resize();
87                 } else if (text) {
88                         delete text;
89                         text = 0;
90                 }
91         }
92
93         /// Update window titles of all users
94         void updateTitles();
95
96         /// Reset autosave timers for all users
97         void resetAutosaveTimers();
98
99         /** Adds the BufferView to the users list.
100           Later this func will insert the BufferView into a real list,
101           not just setting a pointer.
102           */
103         void addUser(BufferView * u) { users = u; }
104
105         /** Removes the BufferView from the users list.
106           Since we only can have one at the moment, we just reset it.
107           */
108         void delUser(BufferView *){ users = 0; }
109
110         ///
111         void update(signed char f);
112
113         ///
114         void redraw() {
115               users->redraw(); 
116               users->fitCursor(); 
117               users->updateScrollbar();
118         }
119
120         /// Open and lock an updatable inset
121         void open_new_inset(UpdatableInset *);
122
123         ///
124         void loadAutoSaveFile();
125         
126         /** Reads a file. 
127             Returns false if it fails.
128             If par is given, the file is inserted. */
129         bool readFile(LyXLex &, LyXParagraph * par = 0);
130         
131         /** Reads a file without header.
132             Returns false, if file is not completely read.
133             If par is given, the file is inserted. */
134         bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
135
136         /// Inserts a lyx file at cursor position. Returns false if it fails.
137         bool insertLyXFile(string const & filename);
138
139         /// Write file. Returns false if unsuccesful.
140         bool writeFile(string const &, bool);
141         
142         ///
143         void writeFileAscii(string const & , int);
144         
145         ///
146         void makeLaTeXFile(string const & filename,
147                            string const & original_path,
148                            bool nice, bool only_body = false);
149
150         ///
151         int runLaTeX();
152
153         ///
154         int runLiterate();
155
156         ///
157         int buildProgram();
158
159         ///
160         int runChktex();
161
162         ///
163         void makeLinuxDocFile(string const & filename, int column);
164         ///
165         void makeDocBookFile(string const & filename, int column);
166
167         /// returns the main language for the buffer (document)
168         string GetLanguage() const {
169                 return params.language;
170         }
171         
172         ///
173         bool isLyxClean() const { return lyx_clean; }
174         
175         /// changed Heinrich Bauer, 23/03/98
176         bool isDviClean();
177         
178         ///
179         bool isNwClean() const { return nw_clean; }
180        
181         ///
182         bool isBakClean() const { return bak_clean; }
183         
184         ///
185         bool isDepClean(string const & name) const;
186         
187         ///
188         void markLyxClean() { 
189                 if (!lyx_clean) {
190                         lyx_clean = true; 
191                         updateTitles();
192                 }
193                 // if the .lyx file has been saved, we don't need an
194                 // autosave 
195                 bak_clean = true;
196         }
197
198         /// changed Heinrich Bauer, 23/03/98
199         void markDviClean();
200         
201         ///
202         void markNwClean() { nw_clean = true; }
203        
204         ///
205         void markBakClean() { bak_clean = true; }
206         
207         ///
208         void markDepClean(string const & name);
209         
210         ///
211         void markDviDirty();
212         
213         ///
214         void markNwDirty() { nw_clean = false; }
215        
216         ///
217         void markDirty() {
218                 if (lyx_clean) {
219                         lyx_clean = false;
220                         updateTitles();
221                 }
222                 dvi_clean_tmpd = false;
223                 dvi_clean_orgd = false;
224                 nw_clean = false;
225                 bak_clean = false;
226                 DEPCLEAN * tmp = dep_clean;
227                 while (tmp) {
228                         tmp->clean = false;
229                         tmp = tmp->next;
230                 }
231         }
232
233         ///
234         string getFileName() const { return filename; }
235
236         /// A transformed version of the file name, adequate for LaTeX  
237         string getLatexName() const {
238                 return ChangeExtension(MakeLatexName(filename), ".tex", true); 
239         }
240
241         /// Change name of buffer. Updates "read-only" flag.
242         void setFileName(string const & newfile);
243
244         /// Name of the document's parent
245         void setParentName(string const &);
246
247         /// Is buffer read-only?
248         bool isReadonly() { return read_only; }
249
250         /// Set buffer read-only flag
251         void setReadonly(bool flag = true) 
252         {
253                 if (read_only != flag) {
254                         read_only = flag; 
255                         updateTitles();
256                         updateAllVisibleBufferRelatedPopups();
257                 }
258                 if (read_only) {
259                         WarnReadonly();
260                 }
261         }
262
263         /// returns true if the buffer contains a LaTeX document
264         bool isLatex() const;
265         /// returns true if the buffer contains a LinuxDoc document
266         bool isLinuxDoc() const;
267         /// returns true if the buffer contains a DocBook document
268         bool isDocBook() const;
269         /// returns true if the buffer contains either a LinuxDoc or DocBook document
270         bool isSGML() const;
271         /// returns true if the buffer contains a Wed document
272         bool isLiterate() const;
273
274         ///
275         void setPaperStuff();
276
277 #if 0
278         ///
279         void setOldPaperStuff();
280 #endif
281         
282         /** Validate a buffer for LaTeX.
283           This validates the buffer, and returns a struct for use by
284           makeLaTeX and others. Its main use is to figure out what commands
285           and packages need to be included in the LaTeX file. It (should)
286           also check that the needed constructs are there (i.e. that the \refs
287           points to coresponding \labels). It should perhaps inset "error"
288           insets to help the user correct obvious mistakes.
289          */
290         void validate(LaTeXFeatures &); //the correct parameters to be
291                                         //included later 
292
293         /** Insert an inset into the buffer
294           Insert inset into buffer, placing it in a layout of lout,
295           if no_table make sure that it doesn't end up in a table. */
296         void insertInset(Inset *, string const & lout = string(), 
297                          bool no_table = false);
298
299         ///
300         void setCursorFromRow (int);
301
302         ///
303         string getIncludeonlyList(char delim = ',');
304         ///
305         string getReferenceList(char delim = '|');
306         ///
307         string getBibkeyList(char delim = '|');
308         ///
309         bool gotoLabel(string const &);
310
311         /// removes all autodeletable insets
312         bool removeAutoInsets();
313
314         /** This will clearly have to change later. Later we can have more
315           than one user per buffer. */
316         BufferView * getUser() const { return users; }
317
318         //@}
319
320         /// Does this mean that this is buffer local?
321         UndoStack undostack;
322         
323         /// Does this mean that this is buffer local? 
324         UndoStack redostack;
325         
326         ///
327         BufferParams params;
328         
329         /** is a list of paragraphs.
330          */
331         LyXParagraph * paragraph;
332         
333         /** This holds the mapping between buffer paragraphs and screen rows.
334             Should be moved to BufferView. (Asger)
335          */
336         LyXText * text;
337
338         ///
339         UpdatableInset * the_locking_inset;
340
341         /// RCS object
342         LyXVC lyxvc;
343
344         /// where the temporaries go if we want them
345         string tmppath;
346
347         ///
348         string filepath;
349
350         /** While writing as LaTeX, tells whether we are
351             doing a 'nice' LaTeX file */
352         bool niceFile;
353 protected:
354         ///
355         void InsetUnlock();
356         
357         ///
358         inline void InsetSleep();
359         
360         ///
361         inline void InsetWakeup();
362         
363         ///
364         bool inset_slept;
365         
366         ///
367         int  slx;
368         ///
369         int sly;
370 private:
371         ///
372         void insertErrors(TeXErrors &);
373
374         ///
375         void linuxDocHandleFootnote(ostream & os,
376                                     LyXParagraph * & par, int const depth);
377         ///
378         void DocBookHandleCaption(ostream & os, string & inner_tag,
379                                   int const depth, int desc_on,
380                                   LyXParagraph * &par);
381         ///
382         void DocBookHandleFootnote(ostream & os,
383                                    LyXParagraph * & par, int const depth);
384         ///
385         void sgmlOpenTag(ostream & os, int depth,
386                          string const & latexname) const;
387         ///
388         void sgmlCloseTag(ostream & os, int depth,
389                           string const & latexname) const;
390         ///
391         void LinuxDocError(LyXParagraph * par, int pos, char const * message);
392         ///
393         void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
394                                   int desc_on, int const depth);
395         ///
396         void SimpleDocBookOnePar(string & file, string & extra,
397                                  LyXParagraph * par, int & desc_on,
398                                  int const depth);
399
400         /// LinuxDoc.
401         void push_tag(ostream & os, char const * tag,
402                       int & pos, char stack[5][3]);
403         
404         /// LinuxDoc.
405         void pop_tag(ostream & os, char const * tag,
406                      int & pos, char stack[5][3]);
407         
408         ///
409         void RoffAsciiTable(ostream &, LyXParagraph * par);
410
411         /// is save needed
412         bool lyx_clean;
413         
414         /// is autosave needed
415         bool bak_clean;
416         
417         /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
418             We have to distinguish between TeX-runs executed in the original
419             directory (in which the original LyX-file resides) and TeX-runs
420             executed in a temporary directory. The first situation is valid
421             for a dvi-export, the latter one for printing or previewing. */
422         bool dvi_clean_orgd;
423         bool dvi_clean_tmpd;
424
425         /// do we need to run weave/tangle
426         bool nw_clean;
427
428         /// is regenerating .tex necessary
429         DEPCLEAN * dep_clean;
430
431         /// buffer is r/o
432         bool read_only;
433
434         /// name of the file the buffer is associated with.
435         string filename;
436
437         /// Format number of buffer
438         float format;
439         
440         /** A list of views using this buffer.
441           Why not keep a list of the BufferViews that use this buffer?
442
443           At least then we don't have to do a lot of magic like:
444           buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
445           of the buffers in the list of users to do a updateLayoutChoice.
446           */
447         BufferView * users;
448
449         ///
450         friend class BufferList;
451         ///
452         friend class BufferView;
453
454         /// Used when typesetting to place errorboxes.
455         TexRow texrow;
456 };
457
458
459 inline  
460 void Buffer::InsetSleep()
461 {
462     if (the_locking_inset && !inset_slept) {
463         the_locking_inset->GetCursorPos(slx, sly);
464         the_locking_inset->InsetUnlock();
465         inset_slept = true;
466     }
467 }
468
469
470 inline  
471 void Buffer::InsetWakeup()
472 {
473     if (the_locking_inset && inset_slept) {
474         the_locking_inset->Edit(slx, sly);
475         inset_slept = false;
476     }   
477 }
478
479
480 inline  
481 void Buffer::setParentName(string const & name)
482 {
483     params.parentname = name;    
484 }
485
486 #endif