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