]> git.lyx.org Git - features.git/blob - src/Buffer.h
Remove unused forward declarations
[features.git] / src / Buffer.h
1 // -*- C++ -*-
2 /**
3  * \file Buffer.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BUFFER_H
13 #define BUFFER_H
14
15 #include "OutputEnums.h"
16
17 #include "support/unique_ptr.h"
18 #include "support/strfwd.h"
19 #include "support/types.h"
20 #include "support/FileNameList.h"
21
22 #include <map>
23 #include <list>
24 #include <set>
25 #include <string>
26 #include <vector>
27
28
29 namespace lyx {
30
31 class BiblioInfo;
32 class BibTeXInfo;
33 class BufferParams;
34 class DispatchResult;
35 class DocIterator;
36 class docstring_list;
37 class ErrorList;
38 class FuncRequest;
39 class FuncStatus;
40 class Inset;
41 class InsetLabel;
42 class Lexer;
43 class Text;
44 class LyXVC;
45 class LaTeXFeatures;
46 class Language;
47 class MacroData;
48 class MacroNameSet;
49 class MacroSet;
50 class OutputParams;
51 class otexstream;
52 class ParConstIterator;
53 class ParIterator;
54 class ParagraphList;
55 class TeXErrors;
56 class TexRow;
57 class TocBackend;
58 class Undo;
59 class WordLangTuple;
60
61 namespace frontend {
62 class GuiBufferDelegate;
63 class WorkAreaManager;
64 } // namespace frontend
65
66 namespace support {
67 class DocFileName;
68 class FileName;
69 } // namespace support
70
71 namespace graphics {
72 class PreviewLoader;
73 class Cache;
74 } // namespace graphics
75
76
77 class Buffer;
78 typedef std::list<Buffer *> ListOfBuffers;
79 /// a list of Buffers we cloned
80 typedef std::set<Buffer *> CloneList;
81 typedef std::shared_ptr<CloneList> CloneList_ptr;
82
83
84 /** The buffer object.
85  * This is the buffer object. It contains all the information about
86  * a document loaded into LyX.
87  * The buffer object owns the Text (wrapped in an InsetText), which
88  * contains the individual paragraphs of the document.
89  *
90  *
91  * I am not sure if the class is complete or
92  * minimal, probably not.
93  * \author Lars Gullik Bjønnes
94  */
95
96 class MarkAsExporting;
97
98 class Buffer {
99 public:
100         /// What type of log will \c getLogName() return?
101         enum LogType {
102                 latexlog, ///< LaTeX log
103                 buildlog  ///< Literate build log
104         };
105
106         /// Result of \c readFile()
107         enum ReadStatus {
108                 ReadSuccess,
109                 ReadCancel,
110                 // failures
111                 ReadFailure,
112                 ReadWrongVersion,
113                 ReadFileNotFound,
114                 ReadVCError,
115                 ReadAutosaveFailure,
116                 ReadEmergencyFailure,
117                 ReadNoLyXFormat,
118                 ReadDocumentFailure,
119                 // lyx2lyx
120                 LyX2LyXNoTempFile,
121                 LyX2LyXNotFound,
122                 LyX2LyXOlderFormat,
123                 LyX2LyXNewerFormat,
124                 // other
125                 ReadOriginal
126         };
127
128         enum ExportStatus {
129                 // export
130                 ExportSuccess,
131                 ExportCancel,
132                 ExportKilled,
133                 ExportError,
134                 ExportNoPathToFormat,
135                 ExportTexPathHasSpaces,
136                 ExportConverterError,
137                 // preview
138                 // Implies ExportSuccess.
139                 PreviewSuccess,
140                 // The exported file exists but there was an error when opening
141                 // it in a viewer.
142                 PreviewError
143         };
144
145         ///
146         enum UpdateScope {
147                 UpdateMaster,
148                 UpdateChildOnly
149         };
150
151         /// Constructor
152         explicit Buffer(std::string const & file, bool readonly = false,
153                 Buffer const * cloned_buffer = nullptr);
154
155         /// Destructor
156         ~Buffer();
157
158         /// Clones the entire structure of which this Buffer is part, 
159         /// cloning all the children, too.
160         Buffer * cloneWithChildren() const;
161         /// Just clones this single Buffer. For autosave.
162         Buffer * cloneBufferOnly() const;
163         ///
164         bool isClone() const;
165
166         /** High-level interface to buffer functionality.
167             This function parses a command string and executes it.
168         */
169         void dispatch(std::string const & command, DispatchResult & result);
170
171         /// Maybe we know the function already by number...
172         void dispatch(FuncRequest const & func, DispatchResult & result);
173
174         /// Can this function be exectued?
175         /// \return true if we made a decision
176         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
177
178         ///
179         DocIterator getParFromID(int id) const;
180         /// do we have a paragraph with this id?
181         bool hasParWithID(int id) const;
182
183         ///
184         frontend::WorkAreaManager & workAreaManager() const;
185
186         /** Save file.
187             Takes care of auto-save files and backup file if requested.
188             Returns \c true if the save is successful, \c false otherwise.
189         */
190         bool save() const;
191         /// Renames and saves the buffer
192         bool saveAs(support::FileName const & fn);
193
194         /// Write document to stream. Returns \c false if unsuccessful.
195         bool write(std::ostream &) const;
196         /// Write file. Returns \c false if unsuccessful.
197         bool writeFile(support::FileName const &) const;
198
199         /// \name Functions involved in reading files/strings.
200         //@{
201         /// Loads the LyX file into the buffer. This function
202         /// tries to extract the file from version control if it
203         /// cannot be found. If it can be found, it will try to
204         /// read an emergency save file or an autosave file.
205         /// \sa loadThisLyXFile
206         ReadStatus loadLyXFile();
207         /// Loads the LyX file \c fn into the buffer. If you want
208         /// to check for files in a version control container,
209         /// emergency or autosave files, one should use \c loadLyXFile.
210         /// /sa loadLyXFile
211         ReadStatus loadThisLyXFile(support::FileName const & fn);
212         /// import a new document from a string
213         bool importString(std::string const &, docstring const &, ErrorList &);
214         /// import a new file
215         bool importFile(std::string const &, support::FileName const &, ErrorList &);
216         /// read a new document from a string
217         bool readString(std::string const &);
218         /// Reloads the LyX file
219         ReadStatus reload();
220 //FIXME: The following function should be private
221 //private:
222         /// read the header, returns number of unknown tokens
223         int readHeader(Lexer & lex);
224
225         double fontScalingFactor() const;
226
227 private:
228         ///
229         typedef std::map<Buffer const *, Buffer *> BufferMap;
230         ///
231         void cloneWithChildren(BufferMap &, CloneList_ptr) const;
232         /// save checksum of the given file.
233         void saveCheckSum() const;
234         /// read a new file
235         ReadStatus readFile(support::FileName const & fn);
236         /// Reads a file without header.
237         /// \param par if != 0 insert the file.
238         /// \return \c true if file is not completely read.
239         bool readDocument(Lexer &);
240         /// Try to extract the file from a version control container
241         /// before reading if the file cannot be found.
242         /// \sa LyXVC::file_not_found_hook
243         ReadStatus extractFromVC();
244         /// Reads the first tag of a LyX File and
245         /// returns the file format number.
246         ReadStatus parseLyXFormat(Lexer & lex, support::FileName const & fn,
247                 int & file_format) const;
248         /// Convert the LyX file to the LYX_FORMAT using
249         /// the lyx2lyx script and returns the filename
250         /// of the temporary file to be read
251         ReadStatus convertLyXFormat(support::FileName const & fn,
252                 support::FileName & tmpfile, int from_format);
253         /// get appropriate name for backing up files from older versions
254         support::FileName getBackupName() const;
255         //@}
256
257 public:
258         /// \name Functions involved in autosave and emergency files.
259         //@{
260         /// Save an autosave file to #filename.lyx#
261         bool autoSave() const;
262         /// save emergency file
263         /// \return a status message towards the user.
264         docstring emergencyWrite();
265
266 //FIXME:The following function should be private
267 //private:
268         ///
269         void removeAutosaveFile() const;
270
271 private:
272         /// Try to load an autosave file associated to \c fn.
273         ReadStatus loadAutosave();
274         /// Try to load an emergency file associated to \c fn.
275         ReadStatus loadEmergency();
276         /// Get the filename of the emergency file associated with the Buffer
277         support::FileName getEmergencyFileName() const;
278         /// Get the filename of the autosave file associated with the Buffer
279         support::FileName getAutosaveFileName() const;
280         ///
281         void moveAutosaveFile(support::FileName const & old) const;
282         //@}
283
284 public:
285         /// Fill in the ErrorList with the TeXErrors
286         void bufferErrors(TeXErrors const &, ErrorList &) const;
287         /// Fill in the Citation/Reference ErrorList from the TeXErrors
288         void bufferRefs(TeXErrors const &, ErrorList &) const;
289
290         enum OutputWhat {
291                 FullSource,
292                 OnlyBody,
293                 IncludedFile,
294                 OnlyPreamble,
295                 CurrentParagraph
296         };
297
298         /// Just a wrapper for writeLaTeXSource, first creating the ofstream.
299         ExportStatus makeLaTeXFile(support::FileName const & filename,
300                            std::string const & original_path,
301                            OutputParams const &,
302                            OutputWhat output = FullSource) const;
303         /** Export the buffer to LaTeX.
304             If \p os is a file stream, and params().inputenc is "auto-legacy" or
305             "auto-legacy-plain", and the buffer contains text in different languages
306             with more than one encoding, then this method will change the
307             encoding associated to \p os. Therefore you must not call this
308             method with a string stream if the output is supposed to go to a
309             file. \code
310             ofdocstream ofs;
311             otexstream os(ofs);
312             ofs.open("test.tex");
313             writeLaTeXSource(os, ...);
314             ofs.close();
315             \endcode is NOT equivalent to \code
316             odocstringstream oss;
317             otexstream os(oss);
318             writeLaTeXSource(os, ...);
319             ofdocstream ofs;
320             ofs.open("test.tex");
321             ofs << oss.str();
322             ofs.close();
323             \endcode
324          */
325         ExportStatus writeLaTeXSource(otexstream & os,
326                            std::string const & original_path,
327                            OutputParams const &,
328                            OutputWhat output = FullSource) const;
329         ///
330         ExportStatus makeDocBookFile(support::FileName const & filename,
331                              OutputParams const & runparams_in,
332                              OutputWhat output = FullSource) const;
333         ///
334         ExportStatus writeDocBookSource(odocstream & os,
335                                  OutputParams const & runparams_in,
336                                  OutputWhat output = FullSource) const;
337         ///
338         ExportStatus makeLyXHTMLFile(support::FileName const & filename,
339                              OutputParams const & runparams_in) const;
340         ///
341         ExportStatus writeLyXHTMLSource(odocstream & os,
342                              OutputParams const & runparams_in,
343                              OutputWhat output = FullSource) const;
344         /// returns the main language for the buffer (document)
345         Language const * language() const;
346         /// get l10n translated to the buffers language
347         docstring B_(std::string const & l10n) const;
348
349         ///
350         int runChktex();
351         /// return true if the main lyx file does not need saving
352         bool isClean() const;
353         ///
354         bool isDepClean(std::string const & name) const;
355
356         /// Whether or not disk file has been externally modified. Uses a checksum
357         /// which is accurate but slow, which can be a problem when it is frequently
358         /// used, or used for a large file on a slow (network) file system.
359         bool isChecksumModified() const;
360
361         /// Flag set by the FileSystemWatcher.
362         /// Fast but (not so) inaccurate, can be cleared by the user.
363         bool notifiesExternalModification() const;
364         void clearExternalModification() const;
365
366         /// mark the main lyx file as not needing saving
367         void markClean() const;
368
369         ///
370         void markDepClean(std::string const & name);
371
372         ///
373         void setUnnamed(bool flag = true);
374
375         /// Whether or not a filename has been assigned to this buffer
376         bool isUnnamed() const;
377
378         /// Whether or not this buffer is internal.
379         ///
380         /// An internal buffer does not contain a real document, but some auxiliary text segment.
381         /// It is not associated with a filename, it is never saved, thus it does not need to be
382         /// automatically saved, nor it needs to trigger any "do you want to save ?" question.
383         bool isInternal() const;
384
385         void setInternal(bool flag);
386
387         /// Mark this buffer as dirty.
388         void markDirty();
389
390         /// Returns the buffer's filename. It is always an absolute path.
391         support::FileName fileName() const;
392
393         /// Returns the buffer's filename. It is always an absolute path.
394         std::string absFileName() const;
395
396         /// Returns the path where the buffer lives.
397         /// It is always an absolute path.
398         std::string filePath() const;
399
400         /** Contructs a file name of a referenced file (child doc, included graphics etc).
401          *  Absolute names are returned as is. If the name is relative, it is
402          *  interpreted relative to filePath() if the file exists, otherwise
403          *  relative to the original path where the document was last saved.
404          *  The original path may be different from filePath() if the document was
405          *  later manually moved to a different location.
406          */
407         support::DocFileName getReferencedFileName(std::string const & fn) const;
408
409         /// Format a file name for LaTeX output (absolute or relative or filename only,
410         /// depending on file and context)
411         std::string const prepareFileNameForLaTeX(std::string const &,
412                                         std::string const &, bool nice) const;
413
414         /** Returns a vector of bibliography (*.bib) file paths suitable for the
415          *  output in the respective BibTeX/Biblatex macro and potential individual encoding
416          */
417         std::vector<std::pair<docstring, std::string>> const prepareBibFilePaths(OutputParams const &,
418                                     const docstring_list & bibfilelist,
419                                     bool const extension = true) const;
420
421         /** Returns the path where a local layout file lives.
422          *  An empty string is returned for standard system and user layouts.
423          *  If possible, it is always relative to the buffer path.
424          */
425         std::string layoutPos() const;
426
427         /** Set the path to a local layout file.
428          *  This must be an absolute path but, if possible, it is always
429          *  stored as relative to the buffer path.
430          */
431         void setLayoutPos(std::string const & path);
432
433         /** A transformed version of the file name, adequate for LaTeX.
434             \param no_path optional if \c true then the path is stripped.
435         */
436         std::string latexName(bool no_path = true) const;
437
438         /// Get the name and type of the log.
439         std::string logName(LogType * type = nullptr) const;
440
441         /// Set document's parent Buffer.
442         void setParent(Buffer const *);
443         Buffer const * parent() const;
444
445         /** Get the document's master (or \c this if this is not a
446             child document)
447          */
448         Buffer const * masterBuffer() const;
449
450         /// \return true if \p child is a child of this \c Buffer.
451         bool isChild(Buffer * child) const;
452
453         /// \return true if this \c Buffer has children
454         bool hasChildren() const;
455
456         /// \return a list of the direct children of this Buffer.
457         /// this list has no duplicates and is in the order in which
458         /// the children appear.
459         ListOfBuffers getChildren() const;
460
461         /// \return a list of all descendants of this Buffer (children,
462         /// grandchildren, etc). this list has no duplicates and is in
463         /// the order in which the children appear.
464         ListOfBuffers getDescendants() const;
465
466         /// Collect all relative buffers, in the order in which they appear.
467         /// I.e., the "root" Buffer is first, then its first child, then any
468         /// of its children, etc. However, there are no duplicates in this
469         /// list.
470         /// This is "stable", too, in the sense that it returns the same
471         /// thing from whichever Buffer it is called.
472         ListOfBuffers allRelatives() const;
473
474         /// Is buffer read-only? True if it has either the read-only flag or the
475         /// externally modified flag.
476         bool isReadonly() const;
477
478         /// Does the buffer have the read-only flag?
479         bool hasReadonlyFlag() const;
480
481         /// Set buffer read-only flag
482         void setReadonly(bool flag = true);
483
484         /** Validate a buffer for LaTeX.
485             This validates the buffer, and returns a struct for use by
486             #makeLaTeX# and others. Its main use is to figure out what
487             commands and packages need to be included in the LaTeX file.
488             It (should) also check that the needed constructs are there
489             (i.e. that the \refs points to coresponding \labels). It
490             should perhaps inset "error" insets to help the user correct
491             obvious mistakes.
492         */
493         void validate(LaTeXFeatures &) const;
494
495         /// Bibliography information is cached in the Buffer, so we do not
496         /// have to check or read things over and over.
497         /// The cache exists only in the master buffer. When it is updated,
498         /// the children add their information to the master's cache.
499         /// Calling this method invalidates the cache and so requires a
500         /// re-read.
501         void invalidateBibinfoCache() const;
502         /// Clear the bibfiles cache
503         void clearBibFileCache() const;
504         /// Updates the cached bibliography information, checking first to see
505         /// whether the cache is valid. If so, we do nothing. If not, then we
506         /// reload all the BibTeX info.
507         /// Note that this operates on the master document.
508         void reloadBibInfoCache(bool const force = false) const;
509         /// \return the bibliography information for this buffer's master,
510         /// or just for it, if it isn't a child.
511         BiblioInfo const & masterBibInfo() const;
512         /// \return this buffer's bibliography information
513         BiblioInfo const & bibInfo() const;
514         /// collect bibliography info from the various insets in this buffer.
515         void collectBibKeys(support::FileNameList &) const;
516         /// add some BiblioInfo to our cache
517         void addBiblioInfo(BiblioInfo const & bi) const;
518         /// add a single piece of bibliography info to our cache
519         void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
520         ///
521         void makeCitationLabels() const;
522         ///
523         void invalidateCiteLabels() const;
524         ///
525         bool citeLabelsValid() const;
526         ///
527         void getLabelList(std::vector<docstring> &) const;
528
529         /// This removes the .aux and .bbl files from the temp dir.
530         void removeBiblioTempFiles() const;
531
532         ///
533         void changeLanguage(Language const * from, Language const * to);
534
535         ///
536         bool isMultiLingual() const;
537         ///
538         std::set<Language const *> getLanguages() const;
539
540         ///
541         BufferParams & params();
542         BufferParams const & params() const;
543         ///
544         BufferParams const & masterParams() const;
545
546         /** The list of paragraphs.
547             This is a linked list of paragraph, this list holds the
548             whole contents of the document.
549          */
550         ParagraphList & paragraphs();
551         ParagraphList const & paragraphs() const;
552
553         /// LyX version control object.
554         LyXVC & lyxvc();
555         LyXVC const & lyxvc() const;
556
557         /// Where to put temporary files.
558         std::string const temppath() const;
559
560         /// Used when typesetting to place errorboxes.
561         TexRow const & texrow() const;
562         TexRow & texrow();
563
564         ///
565         ParIterator par_iterator_begin();
566         ///
567         ParConstIterator par_iterator_begin() const;
568         ///
569         ParIterator par_iterator_end();
570         ///
571         ParConstIterator par_iterator_end() const;
572
573         // Position of the child buffer where it appears first in the master.
574         DocIterator firstChildPosition(Buffer const * child);
575
576         /** \returns true only when the file is fully loaded.
577          *  Used to prevent the premature generation of previews
578          *  and by the citation inset.
579          */
580         bool isFullyLoaded() const;
581         /// Set by buffer_funcs' newFile.
582         void setFullyLoaded(bool);
583
584         /// FIXME: Needed by RenderPreview.
585         graphics::PreviewLoader * loader() const;
586         /// Update the LaTeX preview snippets associated with this buffer
587         void updatePreviews() const;
588         /// Remove any previewed LaTeX snippets associated with this buffer
589         void removePreviews() const;
590         ///
591         graphics::Cache & graphicsCache() const;
592
593         /// Our main text (inside the top InsetText)
594         Text & text() const;
595
596         /// Our top InsetText
597         Inset & inset() const;
598
599         //
600         // Macro handling
601         //
602         /// Collect macro definitions in paragraphs
603         void updateMacros() const;
604         /// Iterate through the whole buffer and try to resolve macros
605         void updateMacroInstances(UpdateType) const;
606
607         /// List macro names of this buffer, the parent and the children
608         void listMacroNames(MacroNameSet & macros) const;
609         /// Collect macros of the parent and its children in front of this buffer.
610         void listParentMacros(MacroSet & macros, LaTeXFeatures & features) const;
611
612         /// Return macro defined before pos (or in the master buffer)
613         MacroData const * getMacro(docstring const & name, DocIterator const & pos, bool global = true) const;
614         /// Return macro defined anywhere in the buffer (or in the master buffer)
615         MacroData const * getMacro(docstring const & name, bool global = true) const;
616         /// Return macro defined before the inclusion of the child
617         MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const;
618
619         /// Collect user macro names at loading time
620         typedef std::set<docstring> UserMacroSet;
621         mutable UserMacroSet usermacros;
622
623         /// Replace the inset contents for insets which InsetCode is equal
624         /// to the passed \p inset_code. Handles undo.
625         void changeRefsIfUnique(docstring const & from, docstring const & to);
626
627         /// get source code (latex/docbook) for some paragraphs, or all paragraphs
628         /// including preamble
629         /// returns nullptr if Id to Row conversion is unsupported
630         unique_ptr<TexRow> getSourceCode(odocstream & os,
631                         std::string const & format, pit_type par_begin,
632                         pit_type par_end, OutputWhat output, bool master) const;
633
634         /// Access to error list.
635         /// This method is used only for GUI visualisation of Buffer related
636         /// errors (like parsing or LateX compilation). This method is const
637         /// because modifying the returned ErrorList does not touch the document
638         /// contents.
639         ErrorList & errorList(std::string const & type) const;
640
641         /// The Toc backend.
642         /// This is useful only for screen visualisation of the Buffer. This
643         /// method is const because modifying this backend does not touch
644         /// the document contents.
645         TocBackend & tocBackend() const;
646
647         ///
648         Undo & undo();
649
650         /// This function is called when the buffer is changed.
651         void changed(bool update_metrics) const;
652         ///
653         void setChild(DocIterator const & dit, Buffer * child);
654         ///
655         void updateTocItem(std::string const &, DocIterator const &) const;
656         /// This function is called when the buffer structure is changed.
657         void structureChanged() const;
658         /// This function is called when some parsing error shows up.
659         void errors(std::string const & err, bool from_master = false) const;
660         /// This function is called when the buffer busy status change.
661         void setBusy(bool on) const;
662         /// Update window titles of all users.
663         void updateTitles() const;
664         /// Reset autosave timers for all users.
665         void resetAutosaveTimers() const;
666         ///
667         void message(docstring const & msg) const;
668
669         ///
670         void setGuiDelegate(frontend::GuiBufferDelegate * gui);
671         ///
672         bool hasGuiDelegate() const;
673
674         ///
675         ExportStatus doExport(std::string const & target, bool put_in_tempdir) const;
676         /// Export buffer to format \p format and open the result in a suitable viewer.
677         /// Note: This has nothing to do with preview of graphics or math formulas.
678         ExportStatus preview(std::string const & format) const;
679         /// true if there was a previous preview this session of this buffer and
680         /// there was an error on the previous preview of this buffer.
681         bool freshStartRequired() const;
682         ///
683         void requireFreshStart(bool const b) const;
684
685 private:
686         ///
687         ExportStatus doExport(std::string const & target, bool put_in_tempdir,
688                 std::string & result_file) const;
689         /// target is a format name optionally followed by a space
690         /// and a destination file-name
691         ExportStatus doExport(std::string const & target, bool put_in_tempdir,
692                 bool includeall, std::string & result_file) const;
693         ///
694         ExportStatus preview(std::string const & format, bool includeall) const;
695         ///
696         void setMathFlavor(OutputParams & op) const;
697
698 public:
699         ///
700         bool isExporting() const;
701
702         /// A collection of InsetRef insets and their position in the buffer
703         typedef std::vector<std::pair<Inset *, ParIterator> > References;
704         /// Get all InsetRef insets and their positions associated with
705         /// the InsetLabel with the label string \p label
706         References const & references(docstring const & label) const;
707         /// Add an InsetRef at position \p it to the Insetlabel
708         /// with the label string \p label
709         void addReference(docstring const & label, Inset * inset, ParIterator it);
710         /// Clear the whole reference cache
711         void clearReferenceCache() const;
712         /// Set the InsetLabel for a given \p label string. \p active
713         /// determines whether this is an active label (see @ref activeLabel)
714         void setInsetLabel(docstring const & label, InsetLabel const * il,
715                            bool const active);
716         /// \return the InsetLabel associated with this \p label string
717         /// If \p active is true we only return active labels
718         /// (see @ref activeLabel)
719         InsetLabel const * insetLabel(docstring const & label,
720                                       bool const active = false) const;
721         /// \return true if this \param label is an active label.
722         /// Inactive labels are currently deleted labels (in ct mode)
723         bool activeLabel(docstring const & label) const;
724
725         /// return a list of all used branches (also in children)
726         void getUsedBranches(std::list<docstring> &, bool const from_master = false) const;
727
728         /// Updates screen labels and some other information associated with
729         /// insets and paragraphs. Actually, it's more like a general "recurse
730         /// through the Buffer" routine, that visits all the insets and paragraphs.
731         void updateBuffer() const { updateBuffer(UpdateMaster, InternalUpdate); }
732         /// \param scope: whether to start with the master document or just
733         /// do this one.
734         /// \param output: whether we are preparing for output.
735         void updateBuffer(UpdateScope scope, UpdateType utype) const;
736         ///
737         void updateBuffer(ParIterator & parit, UpdateType utype, bool const deleted = false) const;
738
739         /// Spellcheck starting from \p from.
740         /// \p from initial position, will then points to the next misspelled
741         ///    word.
742         /// \p to will points to the end of the next misspelled word.
743         /// \p word_lang will contain the found misspelled word.
744         /// \return progress if a new word was found.
745         int spellCheck(DocIterator & from, DocIterator & to,
746                 WordLangTuple & word_lang, docstring_list & suggestions) const;
747         ///
748         void checkChildBuffers();
749         ///
750         void checkMasterBuffer();
751
752         /// If the document is being saved to a new location and the named file
753         /// exists at the old location, return its updated path relative to the
754         /// new buffer path if possible, otherwise return its absolute path.
755         /// In all other cases, this is a no-op and name is returned unchanged.
756         /// If a non-empty ext is given, the existence of name.ext is checked
757         /// but the returned path will not contain this extension.
758         /// Similarly, when loading a document that was moved from the location
759         /// where it was saved, return the correct path relative to the new
760         /// location.
761         std::string includedFilePath(std::string const & name,
762                                 std::string const & ext = empty_string()) const;
763
764         /// compute statistics between \p from and \p to
765         /// \p from initial position
766         /// \p to points to the end position
767         /// \p skipNoOutput if notes etc. should be ignored
768         void updateStatistics(DocIterator & from, DocIterator & to,
769                                                   bool skipNoOutput = true) const;
770         /// statistics accessor functions
771         int wordCount() const;
772         int charCount(bool with_blanks) const;
773
774         /// FIXME: dummy function for now
775         bool areChangesPresent() const;
776
777         ///
778         void registerBibfiles(docstring_list const & bf) const;
779         ///
780         support::FileName getBibfilePath(docstring const & bibid) const;
781
782         /// routines for dealing with possible self-inclusion
783         void pushIncludedBuffer(Buffer const * buf) const;
784         void popIncludedBuffer() const;
785         bool isBufferIncluded(Buffer const * buf) const;
786 private:
787         void clearIncludeList() const;
788
789 private:
790         friend class MarkAsExporting;
791         /// mark the buffer as busy exporting something, or not
792         void setExportStatus(bool e) const;
793
794         ///
795         References & getReferenceCache(docstring const & label);
796         /// Change name of buffer. Updates "read-only" flag.
797         void setFileName(support::FileName const & fname);
798         ///
799         void getLanguages(std::set<Language const *> &) const;
800         /// Checks whether any of the referenced bibfiles have changed since the
801         /// last time we loaded the cache. Note that this does NOT update the
802         /// cached information.
803         void checkIfBibInfoCacheIsValid() const;
804         /// Return the list with all bibfiles in use (including bibfiles
805         /// of loaded child documents).
806         docstring_list const &
807                 getBibfiles(UpdateScope scope = UpdateMaster) const;
808         ///
809         void collectChildren(ListOfBuffers & children, bool grand_children) const;
810
811         /// noncopyable
812         Buffer(Buffer const &);
813         void operator=(Buffer const &);
814
815         /// Use the Pimpl idiom to hide the internals.
816         class Impl;
817         /// The pointer never changes although *pimpl_'s contents may.
818         Impl * const d;
819 };
820
821
822 /// Helper class, to guarantee that the export status
823 /// gets reset properly. To use, simply create a local variable:
824 ///    MarkAsExporting mex(bufptr);
825 /// and leave the rest to us.
826 class MarkAsExporting {
827 public:
828         MarkAsExporting(Buffer const * buf) : buf_(buf)
829         {
830                 buf_->setExportStatus(true);
831         }
832         ~MarkAsExporting()
833         {
834                 buf_->setExportStatus(false);
835         }
836 private:
837         Buffer const * const buf_;
838 };
839
840
841 } // namespace lyx
842
843 #endif