2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
8 * This file is Copyleft (C) 1996
11 * ====================================================== */
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
30 #include "BufferView.h"
32 #include "bufferparams.h"
40 extern void updateAllVisibleBufferRelatedPopups();
41 extern void WarnReadonly();
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.
60 /**@name Constructors and destructor */
63 Buffer(string const & file, LyXRC * lyxrc = 0, bool b = false);
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.
78 bool saveParamsAsDefaults();
80 /// should be changed to work for a list.
91 /// Update window titles of all users
94 /// Reset autosave timers for all users
95 void resetAutosaveTimers();
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.
101 void addUser(BufferView * u) { users = u; }
103 /** Removes the BufferView from the users list.
104 Since we only can have one at the moment, we just reset it.
106 void delUser(BufferView *){ users = 0; }
109 void update(signed char f);
115 users->updateScrollbar();
118 /// Open and lock an updatable inset
119 void open_new_inset(UpdatableInset *);
122 void loadAutoSaveFile();
125 Returns false if it fails.
126 If par is given, the file is inserted. */
127 bool readFile(LyXLex &, LyXParagraph * par = 0);
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);
134 /// Inserts a lyx file at cursor position. Returns false if it fails.
135 bool insertLyXFile(string const & filename);
137 /// Write file. Returns false if unsuccesful.
138 bool writeFile(string const &, bool);
141 void writeFileAscii(string const & , int);
144 void makeLaTeXFile(string const & filename,
145 string const & original_path,
146 bool nice, bool only_body = false);
161 void makeLinuxDocFile(string const & filename, int column);
163 void makeDocBookFile(string const & filename, int column);
165 /// returns the main language for the buffer (document)
166 string GetLanguage() const {
167 return params.language;
171 bool isLyxClean() const { return lyx_clean; }
173 /// changed Heinrich Bauer, 23/03/98
177 bool isNwClean() const { return nw_clean; }
180 bool isBakClean() const { return bak_clean; }
183 bool isDepClean(string const & name) const;
186 void markLyxClean() {
191 // if the .lyx file has been saved, we don't need an
196 /// changed Heinrich Bauer, 23/03/98
200 void markNwClean() { nw_clean = true; }
203 void markBakClean() { bak_clean = true; }
206 void markDepClean(string const & name);
212 void markNwDirty() { nw_clean = false; }
220 dvi_clean_tmpd = false;
221 dvi_clean_orgd = false;
224 DEPCLEAN* tmp = dep_clean;
232 string getFileName() const { return filename; }
234 /// Change name of buffer. Updates "read-only" flag.
235 void setFileName(string const & newfile);
237 /// Name of the document's parent
238 void setParentName(string const &);
240 /// Is buffer read-only?
241 bool isReadonly() { return read_only; }
243 /// Set buffer read-only flag
244 void setReadonly(bool flag = true)
246 if (read_only != flag) {
249 updateAllVisibleBufferRelatedPopups();
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
264 /// returns true if the buffer contains a Wed document
265 bool isLiterate() const;
268 void setPaperStuff();
272 void setOldPaperStuff();
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.
283 void validate(LaTeXFeatures &); //the correct parameters to be
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);
293 void setCursorFromRow (int);
296 string getIncludeonlyList(char delim = ',');
298 string getReferenceList(char delim = '|');
300 string getBibkeyList(char delim = '|');
302 bool gotoLabel(string const &);
304 /// removes all autodeletable insets
305 bool removeAutoInsets();
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; }
313 /// Does this mean that this is buffer local?
316 /// Does this mean that this is buffer local?
322 /** is a list of paragraphs.
324 LyXParagraph * paragraph;
326 /** This holds the mapping between buffer paragraphs and screen rows.
327 Should be moved to BufferView. (Asger)
332 UpdatableInset * the_locking_inset;
337 /// where the temporaries go if we want them
343 /** While writing as LaTeX, tells whether we are
344 doing a 'nice' LaTeX file */
351 inline void InsetSleep();
354 inline void InsetWakeup();
365 void insertErrors(TeXErrors &);
368 void linuxDocHandleFootnote(FILE * file,
369 LyXParagraph * & par, int const depth);
371 void DocBookHandleCaption(FILE * file, string & inner_tag,
372 int const depth, int desc_on,
373 LyXParagraph * &par);
375 void DocBookHandleFootnote(FILE * file,
376 LyXParagraph * & par, int const depth);
378 void sgmlOpenTag(FILE * file, int depth,
379 string const & latexname) const;
381 void sgmlCloseTag(FILE * file, int depth,
382 string const & latexname) const;
384 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
386 void SimpleLinuxDocOnePar(FILE * file, LyXParagraph * par,
387 int desc_on, int const depth);
389 void SimpleDocBookOnePar(string & file, string & extra,
390 LyXParagraph * par, int & desc_on,
394 void push_tag(FILE * file, char const * tag,
395 int & pos, char stack[5][3]);
398 void pop_tag(FILE * file, char const * tag,
399 int & pos, char stack[5][3]);
402 void RoffAsciiTable(FILE * file, LyXParagraph * par);
407 /// is autosave needed
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. */
418 /// do we need to run weave/tangle
421 /// is regenerating .tex necessary
422 DEPCLEAN * dep_clean;
427 /// name of the file the buffer is associated with.
430 /// Format number of buffer
433 /** A list of views using this buffer.
434 Why not keep a list of the BufferViews that use this buffer?
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.
443 friend class BufferList;
445 friend class BufferView;
447 /// Used when typesetting to place errorboxes.
453 void Buffer::InsetSleep()
455 if (the_locking_inset && !inset_slept) {
456 the_locking_inset->GetCursorPos(slx, sly);
457 the_locking_inset->InsetUnlock();
464 void Buffer::InsetWakeup()
466 if (the_locking_inset && inset_slept) {
467 the_locking_inset->Edit(slx, sly);
474 void Buffer::setParentName(string const & name)
476 params.parentname = name;