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;
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.
61 explicit Buffer(string const & file, bool b = false);
66 /** save the buffer's parameters as user default
67 This function saves a file #user_lyxdir/templates/defaults.lyx#
68 which parameters are those of the current buffer. This file
69 is used as a default template when creating a new
70 file. Returns #true# on success.
72 bool saveParamsAsDefaults();
74 /** High-level interface to buffer functionality.
75 This function parses a command string and executes it
77 bool Dispatch(string const & command);
79 /// Maybe we know the function already by number...
80 bool Dispatch(int ac, string const & argument);
82 /// and have an xtl buffer to work with.
83 bool Dispatch(int, auto_mem_buffer &);
85 /// should be changed to work for a list.
88 void resizeInsets(BufferView *);
90 /// Update window titles of all users
91 void updateTitles() const;
93 /// Reset autosave timers for all users
94 void resetAutosaveTimers() const;
96 /** Adds the BufferView to the users list.
97 Later this func will insert the #BufferView# into a real list,
98 not just setting a pointer.
100 void addUser(BufferView * u) { users = u; }
102 /** Removes the #BufferView# from the users list.
103 Since we only can have one at the moment, we just reset it.
105 void delUser(BufferView *) { users = 0; }
110 users->fitCursor(users->text);
111 //users->updateScrollbar();
115 void loadAutoSaveFile();
118 @param par if != 0 insert the file.
119 @return #false# if method fails.
121 bool readFile(LyXLex &, LyXParagraph * par = 0);
123 /** Reads a file without header.
124 @param par if != 0 insert the file.
125 @return false if file is not completely read.
127 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
129 /// This parses a single LyXformat-Token.
130 bool parseSingleLyXformat2Token(LyXLex &, LyXParagraph *& par,
131 LyXParagraph *& return_par,
132 string const & token, int & pos,
133 char & depth, LyXFont &
135 ,LyXParagraph::footnote_flag &,
136 LyXParagraph::footnote_kind &
140 /// Parse a single inset.
141 void readInset(LyXLex &, LyXParagraph *& par, int & pos, LyXFont &);
144 Takes care of auto-save files and backup file if requested.
145 Returns #true# if the save is successful, #false# otherwise.
149 /// Write file. Returns #false# if unsuccesful.
150 bool writeFile(string const &, bool) const;
153 void writeFileAscii(string const & , int);
155 void writeFileAscii(std::ostream &, int);
157 string const asciiParagraph(LyXParagraph const *,
158 unsigned int linelen) const;
160 void makeLaTeXFile(string const & filename,
161 string const & original_path,
162 bool nice, bool only_body = false);
163 /** LaTeX all paragraphs from par to endpar.
164 @param endpar if == 0 then to the end
166 void latexParagraphs(std::ostream & os, LyXParagraph * par,
167 LyXParagraph * endpar, TexRow & texrow) const;
170 void SimpleDocBookOnePar(std::ostream &, string & extra,
171 LyXParagraph * par, int & desc_on,
178 void makeLinuxDocFile(string const & filename,
179 bool nice, bool only_body = false);
181 void makeDocBookFile(string const & filename,
182 bool nice, bool only_body = false);
184 /// returns the main language for the buffer (document)
185 Language const * GetLanguage() const {
186 return params.language;
190 bool isLyxClean() const { return lyx_clean; }
193 bool isBakClean() const { return bak_clean; }
196 bool isDepClean(string const & name) const;
199 void markLyxClean() const {
204 // if the .lyx file has been saved, we don't need an
210 void markBakClean() { bak_clean = true; }
213 void markDepClean(string const & name);
216 void setUnnamed(bool flag=true) { unnamed = flag; }
219 bool isUnnamed() { return unnamed; }
228 DEPCLEAN * tmp = dep_clean;
236 string const & fileName() const { return filename; }
238 /** A transformed version of the file name, adequate for LaTeX
239 The path is stripped if no_path is true (default)
241 string const getLatexName(bool no_path = true) const;
243 /// Change name of buffer. Updates "read-only" flag.
244 void setFileName(string const & newfile);
246 /// Name of the document's parent
247 void setParentName(string const &);
249 /// Is buffer read-only?
250 bool isReadonly() const { return read_only; }
252 /// Set buffer read-only flag
253 void setReadonly(bool flag = true);
255 /// returns #true# if the buffer contains a LaTeX document
256 bool isLatex() const;
257 /// returns #true# if the buffer contains a LinuxDoc document
258 bool isLinuxDoc() const;
259 /// returns #true# if the buffer contains a DocBook document
260 bool isDocBook() const;
261 /** returns #true# if the buffer contains either a LinuxDoc
262 or DocBook document */
264 /// returns #true# if the buffer contains a Wed document
265 bool isLiterate() const;
268 void setPaperStuff();
270 /** Validate a buffer for LaTeX.
271 This validates the buffer, and returns a struct for use by
272 #makeLaTeX# and others. Its main use is to figure out what
273 commands and packages need to be included in the LaTeX file.
274 It (should) also check that the needed constructs are there
275 (i.e. that the \refs points to coresponding \labels). It
276 should perhaps inset "error" insets to help the user correct
279 void validate(LaTeXFeatures &) const;
282 string const getIncludeonlyList(char delim = ',');
284 std::vector<std::pair<string,string> > const getBibkeyList();
306 std::vector<std::vector<TocItem> > const getTocList() const;
308 std::vector<string> const getLabelList();
310 /** This will clearly have to change later. Later we can have more
311 than one user per buffer. */
312 BufferView * getUser() const { return users; }
315 void ChangeLanguage(Language const * from, Language const * to);
317 bool isMultiLingual();
319 /// Does this mean that this is buffer local?
322 /// Does this mean that this is buffer local?
328 /** is a list of paragraphs.
330 LyXParagraph * paragraph;
335 /// where the temporaries go if we want them
341 /** While writing as LaTeX, tells whether we are
342 doing a 'nice' LaTeX file */
345 /// Used when typesetting to place errorboxes.
350 void linuxDocHandleFootnote(std::ostream & os,
351 LyXParagraph * & par, int depth);
354 void DocBookHandleCaption(std::ostream & os, string & inner_tag,
355 int depth, int desc_on,
356 LyXParagraph * & par);
359 void DocBookHandleFootnote(std::ostream & os,
360 LyXParagraph * & par, int depth);
363 void sgmlOpenTag(std::ostream & os, int depth,
364 string const & latexname) const;
366 void sgmlCloseTag(std::ostream & os, int depth,
367 string const & latexname) const;
369 void LinuxDocError(LyXParagraph * par, int pos,
370 string const & message);
372 void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par,
373 int desc_on, int depth);
376 void push_tag(std::ostream & os, string const & tag,
377 int & pos, char stack[5][3]);
380 void pop_tag(std::ostream & os, string const & tag,
381 int & pos, char stack[5][3]);
384 mutable bool lyx_clean;
386 /// is autosave needed
387 mutable bool bak_clean;
389 /// is this a unnamed file (New...)
392 /// is regenerating #.tex# necessary
393 DEPCLEAN * dep_clean;
398 /// name of the file the buffer is associated with.
401 /// Format number of buffer
407 /** A list of views using this buffer.
408 Why not keep a list of the BufferViews that use this buffer?
410 At least then we don't have to do a lot of magic like:
411 #buffer->lyx_gui->bufferview->updateLayoutChoice#. Just ask each
412 of the buffers in the list of users to do a #updateLayoutChoice#.
418 class inset_iterator {
420 typedef std::input_iterator_tag iterator_category;
421 typedef Inset value_type;
422 typedef ptrdiff_t difference_type;
423 typedef Inset * pointer;
424 typedef Inset & reference;
428 inset_iterator() : par(0) /*, it(0)*/ {}
430 inset_iterator(LyXParagraph * paragraph) : par(paragraph) {
434 inset_iterator(LyXParagraph * paragraph,
435 LyXParagraph::size_type pos);
437 inset_iterator & operator++() { // prefix ++
440 if (it == par->inset_iterator_end()) {
448 inset_iterator operator++(int) { // postfix ++
449 inset_iterator tmp(par, it.getPos());
452 if (it == par->inset_iterator_end()) {
460 Inset * operator*() { return *it; }
463 LyXParagraph * getPar() { return par; }
465 LyXParagraph::size_type getPos() const { return it.getPos(); }
468 bool operator==(inset_iterator const & iter1,
469 inset_iterator const & iter2);
472 //bool operator!=(inset_iterator const & iter1,
473 // inset_iterator const & iter2);
480 LyXParagraph::inset_iterator it;
484 inset_iterator inset_iterator_begin() {
485 return inset_iterator(paragraph);
488 inset_iterator inset_iterator_end() {
489 return inset_iterator();
495 void Buffer::setParentName(string const & name)
497 params.parentname = name;
502 bool operator==(Buffer::TocItem const & a, Buffer::TocItem const & b) {
503 return a.par == b.par && a.str == b.str;
504 // No need to compare depth.
510 bool operator!=(Buffer::TocItem const & a, Buffer::TocItem const & b) {
512 // No need to compare depth.
517 bool operator==(Buffer::inset_iterator const & iter1,
518 Buffer::inset_iterator const & iter2) {
519 return iter1.par == iter2.par
520 && (iter1.par == 0 || iter1.it == iter2.it);
525 bool operator!=(Buffer::inset_iterator const & iter1,
526 Buffer::inset_iterator const & iter2) {
527 return !(iter1 == iter2);