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