2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
8 * This file is Copyleft 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
31 #include "BufferView.h"
33 #include "bufferparams.h"
40 class auto_mem_buffer;
52 /** The buffer object.
53 The is is the buffer object. It contains all the informations about
54 a document loaded into LyX. I am not sure if the class is complete or
55 minimal, probably not.
60 explicit Buffer(string const & file, bool b = false);
65 /** save the buffer's parameters as user default
66 This function saves a file #user_lyxdir/templates/defaults.lyx#
67 which parameters are those of the current buffer. This file
68 is used as a default template when creating a new
69 file. Returns #true# on success.
71 bool saveParamsAsDefaults();
73 /** High-level interface to buffer functionality.
74 This function parses a command string and executes it
76 bool Dispatch(string const & command);
78 /// Maybe we know the function already by number...
79 bool Dispatch(int ac, string const & argument);
81 /// and have an xtl buffer to work with.
82 bool Dispatch(int, auto_mem_buffer &);
84 /// should be changed to work for a list.
87 void resizeInsets(BufferView *);
89 /// Update window titles of all users
90 void updateTitles() const;
92 /// Reset autosave timers for all users
93 void resetAutosaveTimers() const;
95 /** Adds the BufferView to the users list.
96 Later this func will insert the #BufferView# into a real list,
97 not just setting a pointer.
99 void addUser(BufferView * u) { users = u; }
101 /** Removes the #BufferView# from the users list.
102 Since we only can have one at the moment, we just reset it.
104 void delUser(BufferView *) { users = 0; }
110 //users->updateScrollbar();
114 void loadAutoSaveFile();
117 @param par if != 0 insert the file.
118 @return #false# if method fails.
120 bool readFile(LyXLex &, LyXParagraph * par = 0);
122 /** Reads a file without header.
123 @param par if != 0 insert the file.
124 @return false if file is not completely read.
126 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
128 /// This parses a single LyXformat-Token.
129 bool parseSingleLyXformat2Token(LyXLex &, LyXParagraph *& par,
130 LyXParagraph *& return_par,
131 string const & token, int & pos,
132 char & depth, LyXFont &
134 ,LyXParagraph::footnote_flag &,
135 LyXParagraph::footnote_kind &
139 /// Parse a single inset.
140 void readInset(LyXLex &, LyXParagraph *& par, int & pos, LyXFont &);
143 Takes care of auto-save files and backup file if requested.
144 Returns #true# if the save is successful, #false# otherwise.
148 /// Write file. Returns #false# if unsuccesful.
149 bool writeFile(string const &, bool) const;
152 void writeFileAscii(string const & , int);
155 void makeLaTeXFile(string const & filename,
156 string const & original_path,
157 bool nice, bool only_body = false);
158 /** LaTeX all paragraphs from par to endpar.
159 @param endpar if == 0 then to the end
161 void latexParagraphs(std::ostream & os, LyXParagraph * par,
162 LyXParagraph * endpar, TexRow & texrow) const;
174 void makeLinuxDocFile(string const & filename,
175 bool nice, bool only_body = false);
177 void makeDocBookFile(string const & filename,
178 bool nice, bool only_body = false);
180 /// returns the main language for the buffer (document)
181 string const GetLanguage() const {
182 return params.language;
186 bool isLyxClean() const { return lyx_clean; }
189 bool isNwClean() const { return nw_clean; }
192 bool isBakClean() const { return bak_clean; }
195 bool isDepClean(string const & name) const;
198 void markLyxClean() const {
203 // if the .lyx file has been saved, we don't need an
209 void markNwClean() { nw_clean = true; }
212 void markBakClean() { bak_clean = true; }
215 void markDepClean(string const & name);
218 void markNwDirty() { nw_clean = false; }
221 void setUnnamed(bool flag=true) { unnamed = flag; }
224 bool isUnnamed() { return unnamed; }
234 DEPCLEAN * tmp = dep_clean;
242 string const & fileName() const { return filename; }
244 /** A transformed version of the file name, adequate for LaTeX
245 The path is stripped if no_path is true (default)
247 string const getLatexName(bool no_path = true) const;
249 /// Change name of buffer. Updates "read-only" flag.
250 void fileName(string const & newfile);
252 /// Name of the document's parent
253 void setParentName(string const &);
255 /// Is buffer read-only?
256 bool isReadonly() const { return read_only; }
258 /// Set buffer read-only flag
259 void setReadonly(bool flag = true);
261 /// returns #true# if the buffer contains a LaTeX document
262 bool isLatex() const;
263 /// returns #true# if the buffer contains a LinuxDoc document
264 bool isLinuxDoc() const;
265 /// returns #true# if the buffer contains a DocBook document
266 bool isDocBook() const;
267 /** returns #true# if the buffer contains either a LinuxDoc
268 or DocBook document */
270 /// returns #true# if the buffer contains a Wed document
271 bool isLiterate() const;
274 void setPaperStuff();
276 /** Validate a buffer for LaTeX.
277 This validates the buffer, and returns a struct for use by
278 #makeLaTeX# and others. Its main use is to figure out what
279 commands and packages need to be included in the LaTeX file.
280 It (should) also check that the needed constructs are there
281 (i.e. that the \refs points to coresponding \labels). It
282 should perhaps inset "error" insets to help the user correct
285 void validate(LaTeXFeatures &) const;
288 string const getIncludeonlyList(char delim = ',');
290 std::vector<std::pair<string,string> > const getBibkeyList();
312 std::vector<std::vector<TocItem> > const getTocList();
314 std::vector<string> const getLabelList();
316 /** This will clearly have to change later. Later we can have more
317 than one user per buffer. */
318 BufferView * getUser() const { return users; }
321 void ChangeLanguage(Language const * from, Language const * to);
323 bool isMultiLingual();
325 /// Does this mean that this is buffer local?
328 /// Does this mean that this is buffer local?
334 /** is a list of paragraphs.
336 LyXParagraph * paragraph;
341 /// where the temporaries go if we want them
347 /** While writing as LaTeX, tells whether we are
348 doing a 'nice' LaTeX file */
351 /// Used when typesetting to place errorboxes.
356 void linuxDocHandleFootnote(std::ostream & os,
357 LyXParagraph * & par, int const depth);
360 void DocBookHandleCaption(std::ostream & os, string & inner_tag,
361 int const depth, int desc_on,
362 LyXParagraph * & par);
365 void DocBookHandleFootnote(std::ostream & os,
366 LyXParagraph * & par, int const depth);
369 void sgmlOpenTag(std::ostream & os, int depth,
370 string const & latexname) const;
372 void sgmlCloseTag(std::ostream & os, int depth,
373 string const & latexname) const;
375 void LinuxDocError(LyXParagraph * par, int pos,
376 string const & message);
378 void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par,
379 int desc_on, int const depth);
381 void SimpleDocBookOnePar(std::ostream &, string & extra,
382 LyXParagraph * par, int & desc_on,
386 void push_tag(std::ostream & os, string const & tag,
387 int & pos, char stack[5][3]);
390 void pop_tag(std::ostream & os, string const & tag,
391 int & pos, char stack[5][3]);
394 mutable bool lyx_clean;
396 /// is autosave needed
397 mutable bool bak_clean;
399 /// do we need to run weave/tangle
402 /// is this a unnamed file (New...)
405 /// is regenerating #.tex# necessary
406 DEPCLEAN * dep_clean;
411 /// name of the file the buffer is associated with.
414 /// Format number of buffer
417 /** A list of views using this buffer.
418 Why not keep a list of the BufferViews that use this buffer?
420 At least then we don't have to do a lot of magic like:
421 #buffer->lyx_gui->bufferview->updateLayoutChoice#. Just ask each
422 of the buffers in the list of users to do a #updateLayoutChoice#.
428 class inset_iterator {
431 inset_iterator() : par(0) /*, it(0)*/ {}
433 inset_iterator(LyXParagraph * paragraph) : par(paragraph) {
437 inset_iterator(LyXParagraph * paragraph,
438 LyXParagraph::size_type pos);
440 inset_iterator & operator++() {
443 if (it == par->inset_iterator_end()) {
451 Inset * operator*() {return *it; }
453 LyXParagraph * getPar() { return par; }
455 LyXParagraph::size_type getPos() {return it.getPos(); }
458 bool operator==(inset_iterator const & iter1,
459 inset_iterator const & iter2);
462 //bool operator!=(inset_iterator const & iter1,
463 // inset_iterator const & iter2);
470 LyXParagraph::inset_iterator it;
474 inset_iterator inset_iterator_begin() {
475 return inset_iterator(paragraph);
478 inset_iterator inset_iterator_end() {
479 return inset_iterator();
485 void Buffer::setParentName(string const & name)
487 params.parentname = name;
492 bool operator==(Buffer::TocItem const & a, Buffer::TocItem const & b) {
493 return a.par == b.par && a.str == b.str;
494 // No need to compare depth.
500 bool operator!=(Buffer::TocItem const & a, Buffer::TocItem const & b) {
502 // No need to compare depth.
507 bool operator==(Buffer::inset_iterator const & iter1,
508 Buffer::inset_iterator const & iter2) {
509 return iter1.par == iter2.par
510 && (iter1.par == 0 || iter1.it == iter2.it);
515 bool operator!=(Buffer::inset_iterator const & iter1,
516 Buffer::inset_iterator const & iter2) {
517 return !(iter1 == iter2);