home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / buffer.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  9KB  |  408 lines

  1. // -*- C++ -*-
  2. /* This file is part of
  3. * ======================================================
  4. *           LyX, The Document Processor      
  5. *        Copyright (C) 1995 Matthias Ettrich
  6. *
  7. *           This file is Copyleft (C) 1996
  8. *           Lars Gullik Bj°nnes
  9. *
  10. *======================================================*/
  11.  
  12. #ifndef _BUFFER_H_
  13. #define _BUFFER_H_
  14.  
  15. #ifdef __GNUG__
  16. #pragma interface
  17. #endif
  18.  
  19. #include "undo.h"
  20. #include "BufferView.h"
  21. #include "lyxvc.h"
  22. #include "bufferparams.h"
  23. #include "texrow.h"
  24. #include "lyxtext.h"
  25.  
  26. class LyXRC;
  27. class TeXErrors;
  28. class LaTeXFeatures;
  29.  
  30. struct DEPCLEAN {
  31.     bool clean;
  32.     LString master;
  33.     DEPCLEAN *next;
  34. };
  35.  
  36. /** The buffer object.
  37.   The is is the buffer object. It contains all the informations about
  38.   a document loaded into LyX. I am not sure if the class is complete or
  39.   minimal, probably not.
  40.   */
  41. class Buffer {
  42. public:
  43.     /**@name Constructors and destructor */
  44.     //@{
  45.     ///
  46.     Buffer(LString const & file, LyXRC * lyxrc = NULL, bool b= false);
  47.     
  48.     ///
  49.     ~Buffer();
  50.     //@}
  51.  
  52.     /**@name Methods */
  53.     //@{
  54.  
  55.     /** save the buffer's parameters as user default
  56.        This function saves a file user_lyxdir/templates/defaults.lyx 
  57.       which parameters are those of the current buffer. This file
  58.       is used as a default template when creating a new
  59.       file. Returns true on success.
  60.       */
  61.     bool saveParamsAsDefaults();
  62.  
  63.     /// should be changed to work for a list.
  64.     void resize()
  65.     {
  66.         if (users) {
  67.             users->resize();
  68.         } else if (text) {
  69.             delete text;
  70.             text = 0;
  71.         }
  72.     }
  73.  
  74.     /// Update window titles of all users
  75.     void updateTitles();
  76.  
  77.     /// Reset autosave timers for all users
  78.     void resetAutosaveTimers();
  79.  
  80.     /** Adds the BufferView to the users list.
  81.       Later this func will insert the BufferView into a real list,
  82.       not just setting a pointer.
  83.       */
  84.     void addUser(BufferView *u) { users = u; }
  85.  
  86.     /** Removes the BufferView from the users list.
  87.        Since we only can have one at the moment, we just reset it.
  88.       */
  89.     void delUser(BufferView *){ users = 0; }
  90.  
  91.     ///
  92.     void update(signed char f);
  93.  
  94.     ///
  95.     void redraw(void){
  96.               users->redraw(); 
  97.               users->fitCursor(); 
  98.               users->updateScrollbar(); }
  99.  
  100.         /// Open and lock an updatable inset
  101.         void open_new_inset(UpdatableInset*);
  102.  
  103.     ///
  104.     void loadAutoSaveFile();
  105.     
  106.     /** Reads a file. 
  107.         Returns false if it fails.
  108.         If par is given, the file is inserted. */
  109.     bool readFile(LyXLex &, LyXParagraph *par = 0);
  110.     
  111.     /** Reads a file without header.
  112.         Returns false, if file is not completely read.
  113.         If par is given, the file is inserted. */
  114.     bool readLyXformat2(LyXLex &,LyXParagraph *par = 0);
  115.  
  116.     /// Inserts a lyx file at cursor position. Returns false if it fails.
  117.     bool insertLyXFile(LString const & filename);
  118.  
  119.     /// Write file. Returns false if unsuccesful.
  120.     bool writeFile(LString const &, bool);
  121.     
  122.     ///
  123.     void writeFileAscii(LString const & , int);
  124.     
  125.     ///
  126.     void makeLaTeXFile(LString const & filename,
  127.                LString const & original_path,
  128.                bool nice, bool only_body = false);
  129.  
  130.     ///
  131.     int runLaTeX();
  132.  
  133.     ///
  134.     int runChktex();
  135.  
  136.     ///
  137.     void makeLinuxDocFile(LString const & filename, int column);
  138.  
  139.     /// returns the main language for the buffer (document)
  140.     LString GetLanguage() const {
  141.         return params.language;
  142.     }
  143.     
  144.     ///
  145.     bool isLyxClean() const { return lyx_clean; }
  146.     
  147.     ///
  148.     bool isDviClean() const { return dvi_clean; }
  149.     
  150.     ///
  151.     bool isBakClean() const { return bak_clean; }
  152.     
  153.     ///
  154.     bool isDepClean(LString const & name) const;
  155.     
  156.     ///
  157.     void markLyxClean() { 
  158.         if (!lyx_clean) {
  159.             lyx_clean = true; 
  160.             updateTitles();
  161.         }
  162.     }
  163.  
  164.     ///
  165.     void markDviClean() { dvi_clean = true; }
  166.     
  167.     ///
  168.     void markBakClean() { bak_clean = true; }
  169.     
  170.     ///
  171.     void markDepClean(LString const & name);
  172.     
  173.     ///
  174.     void markDviDirty() { dvi_clean = false; }
  175.     
  176.     ///
  177.     void markDirty() {
  178.         if (lyx_clean) {
  179.             lyx_clean = false;
  180.             updateTitles();
  181.         }
  182.         dvi_clean = false;
  183.         bak_clean = false;
  184.         DEPCLEAN* tmp = dep_clean;
  185.         while (tmp) {
  186.             tmp->clean = false;
  187.             tmp = tmp->next;
  188.         }
  189.     }
  190.  
  191.     ///
  192.     LString getFileName() const { return filename; }
  193.  
  194.     /// Change name of buffer. Updates "read-only" flag.
  195.     void setFileName(LString const & newfile);
  196.  
  197.     /// Is buffer read-only?
  198.     bool isReadonly() { return read_only; }
  199.  
  200.     /// Set buffer read-only flag
  201.     void setReadonly(bool flag = true) 
  202.     {
  203.         if (read_only != flag) {
  204.             read_only = flag; 
  205.             updateTitles();
  206.         }
  207.     }
  208.  
  209.     ///
  210.     bool isLinuxDoc();
  211.  
  212.     ///
  213.     void setPaperStuff();
  214.  
  215.     ///
  216.     void setOldPaperStuff();
  217.     
  218.     /** Validate a buffer for LaTeX.
  219.       This validates the buffer, and returns a struct for use by
  220.       makeLaTeX and others. Its main use is to figure out what commands
  221.       and packages need to be included in the LaTeX file. It (should)
  222.       also check that the needed constructs are there (i.e. that the \refs
  223.       points to coresponding \labels). It should behaps inset "error"
  224.       insets to help the user correct obvious mistakes.
  225.      */
  226.     void validate(LaTeXFeatures&); //the correct parameters to be
  227.                        //included later 
  228.  
  229.     /** Insert an inset into the buffer
  230.       Insert inset into buffer, placing it in a layout of lout,
  231.       if no_table make sure that it doesn't end up in a table. */
  232.     void insertInset(Inset *, LString const &lout=LString(), 
  233.              bool no_table = false);
  234.     ///
  235.     LString getIncludeonlyList(char delim=',');
  236.     ///
  237.     LString getReferenceList(char delim='|');
  238.     ///
  239.     bool gotoLabel(const LString&);
  240.  
  241.     /// removes all autodeletable insets
  242.     bool removeAutoInsets();
  243.  
  244.     /** This will clearly have to change later. Later we can have more
  245.       than one user per buffer. */
  246.     BufferView* getUser() const { return users; }
  247.  
  248.         //@}
  249.  
  250.     /// Does this mean that this is buffer local?
  251.         UndoStack undostack;
  252.     
  253.     /// Does this mean that this is buffer local? 
  254.         UndoStack redostack;
  255.     
  256.     ///
  257.     BufferParams params;
  258.     
  259.     /** is a list of paragraphs.
  260.      */
  261.     LyXParagraph *paragraph;
  262.     
  263.     /** This holds the mapping between buffer paragraphs and screen rows.
  264.         Should be moved to BufferView. (Asger)
  265.      */
  266.     LyXText *text;
  267.  
  268.     ///
  269.     UpdatableInset* the_locking_inset;
  270.  
  271.     /// RCS object
  272.     LyXVC lyxvc;
  273.  
  274.     /// where the temporaries go if we want them
  275.     LString tmppath;
  276.  
  277.     ///
  278.     LString filepath;
  279.  
  280.     /// While writing as LaTeX, tells whether we are doing a 'nice' LaTeX file
  281.     bool niceFile;
  282. protected:
  283.     ///
  284.         void InsetUnlock();
  285.     
  286.     ///
  287.         inline void InsetSleep();
  288.     
  289.     ///
  290.         inline void InsetWakeup();
  291.     
  292.     ///
  293.         bool inset_slept;
  294.     
  295.     ///
  296.         int  slx, sly;
  297. private:
  298.     ///
  299.     void insertErrors(TeXErrors &);
  300.     
  301.     ///
  302.         void linuxDocInitVars();
  303.         ///
  304.         void linuxDocHandleFootnote(LyXParagraph*&par);
  305.         ///
  306.         void linuxDocStartPar(FILE *file, LyXParagraph*&par);
  307.         ///
  308.     void linuxDocOnePar(FILE*, LyXParagraph*&);
  309.         ///
  310.         bool linuxDocConvertChar(char c, LString &sgml_string);
  311.     ///
  312.     void SimpleLinuxDocOnePar(FILE *file, LyXFont &font1, 
  313.                   LyXParagraph *par, bool &verb_on, 
  314.                   int &desc_on);
  315.  
  316.     ///
  317.     void LinuxDocError(LyXParagraph *par, int pos, LString const &message);
  318.  
  319.     ///
  320.     int LinuxDocTag(LString const & layout);
  321.  
  322.     /** Gets next LinuxDoc parameter.
  323.       
  324.       This is one of the methods I don't understand. What is its
  325.       purpose? Can somebody explain please?
  326.           Yes. It's used in multi-inset-Insets ;-). Terrible. Should be 
  327.           redesigned, if we switch to LaTeX-based LyX-file. But at 
  328.           moment, e.g. URL-Insets split up into three inset-parts. 
  329.           Firstly \url{. Then comes text [text1]. After this as second
  330.           inset {} and again "normal" text[text2]. And a closing (third)
  331.           } - Inset. GetNextParameter() now reads a text inbetween
  332.           to Insets and handles further insets, which are allowed to 
  333.           arise inside such a construction.
  334.      */
  335.     int GetNextParameter(LyXParagraph *par, int pos, LString &buffer, bool convert);
  336.  
  337.     /// LinuxDoc.
  338.     void push_tag(FILE *file, char const *tag, int& pos, char stack[5][3]);
  339.     
  340.     /// LinuxDoc.
  341.     void pop_tag(FILE *file, char const * tag, int& pos, char stack[5][3]);
  342.  
  343.     ///
  344.     void RoffAsciiTable(FILE *file, LyXParagraph *par);
  345.  
  346.     /// is save needed
  347.     bool lyx_clean;
  348.     
  349.     /// is autosave needed
  350.     bool bak_clean;
  351.     
  352.     /// do we need to run LaTeX
  353.     bool dvi_clean;
  354.  
  355.     /// is regenerating .tex necessary
  356.     DEPCLEAN *dep_clean;
  357.  
  358.     /// buffer is r/o
  359.     bool read_only;
  360.  
  361.     /// name of the file the buffer is associated with.
  362.     LString filename;
  363.  
  364.     /// Format number of buffer
  365.     float format;
  366.     
  367.     /** A list of views using this buffer.
  368.       Why not keep a list of the BufferViews that use this buffer?
  369.  
  370.       At least then we don't have to do a lot of magic like:
  371.       buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
  372.       of the buffers in the list of users to do a updateLayoutChoice.
  373.       */
  374.     BufferView *users;
  375.  
  376.     ///
  377.     friend class BufferList;
  378.     ///
  379.         friend class BufferView;
  380.  
  381.     /// Used when typesetting to place errorboxes.
  382.     TexRow texrow;
  383. };
  384.  
  385.  
  386. inline  
  387. void Buffer::InsetSleep()
  388. {
  389.     if (the_locking_inset && !inset_slept) {
  390.     the_locking_inset->GetCursorPos(slx, sly);
  391.         the_locking_inset->InsetUnlock();
  392.     inset_slept = true;
  393.     }
  394. }
  395.  
  396.  
  397. inline  
  398. void Buffer::InsetWakeup()
  399. {
  400.     if (the_locking_inset && inset_slept) {
  401.     the_locking_inset->Edit(slx, sly);
  402.     inset_slept = false;
  403.     }    
  404. }
  405.  
  406. #endif
  407.