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 / insetinclude.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  4KB  |  185 lines

  1. // -*- C++ -*-
  2. /* This file is part of*
  3.  * ======================================================
  4.  *
  5.  *           LyX, The Document Processor
  6.  *      
  7.  *        Copyright (C) 1997 LyX Team (this file was created this year)
  8.  * 
  9.  *======================================================*/
  10.  
  11. #ifndef _INSET_INCLUDE_H
  12. #define _INSET_INCLUDE_H
  13.  
  14. #ifdef __GNUG__
  15. #pragma interface
  16. #endif
  17.  
  18. #include "insetcommand.h"
  19. #include "buffer.h"
  20. #include "filetools.h"
  21.  
  22. struct LaTeXFeatures;
  23.  
  24. // Created by AAS 970521
  25.  
  26. /**  Used to include files
  27.  */
  28. class InsetInclude: public InsetCommand {
  29. public:
  30.     ///
  31.     InsetInclude(): InsetCommand("include")
  32.     {
  33.         flag = InsetInclude::INCLUDE;
  34.     }
  35.     ///
  36.     InsetInclude(LString const &,  Buffer*);
  37.     ///
  38.     ~InsetInclude();
  39.         ///
  40.         Inset* Clone() { return new InsetInclude (contents, master); }
  41.     ///
  42.     Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; }
  43.     ///
  44.     void Edit(int, int);
  45.     ///
  46.     unsigned char Editable() const
  47.     {
  48.         return 1;
  49.     }
  50.         /// With lyx3 we won't overload these 3 methods
  51.         void Write(FILE *);
  52.         ///
  53.     void Read(LyXLex &);
  54.     /// 
  55.     int Latex(FILE *file, signed char fragile);
  56.     ///
  57.     int Latex(LString &file, signed char fragile);
  58.     
  59.     ///
  60.     void Validate(LaTeXFeatures &) const;
  61.     
  62.         /// Input inserts anything inside a paragraph, Display can give some visual feedback
  63.     bool Display() const { return !(isInput()); }
  64.     ///
  65.     LString getScreenLabel() const;
  66.     ///
  67.     void setContents(LString const & c) {
  68.         InsetCommand::setContents(c);
  69.         filename = MakeAbsPath(contents, 
  70.                        OnlyPath(getMasterFilename())); 
  71.     }
  72.         ///
  73.         void setFilename(LString const & n) { setContents(n); }
  74.         ///
  75.         LString getMasterFilename() const { return master->getFileName(); }
  76.         ///
  77.         LString getFileName() const { 
  78.         return filename;
  79.     }
  80.         ///  In "input" mode uses \input instead of \include.
  81.     bool isInput() const { return (bool)(flag == InsetInclude::INPUT); }
  82.         ///  If this is true, the child file shouldn't be loaded by lyx
  83.     bool isNoLoad() const { return (bool)(noload); }
  84.  
  85.         /**  A verbatim file shouldn't be loaded by LyX
  86.      *  No need to generate LaTeX code of a verbatim file
  87.      */ 
  88.     bool isVerb() const;
  89.     ///
  90.     bool isVerbVisibleSpace() const { return (bool)(flag==InsetInclude::VERBAST);}
  91.         ///  
  92.     bool isInclude() const { return (bool)(flag == InsetInclude::INCLUDE);}
  93.         ///  
  94.     void setInput();
  95.         ///  
  96.     void setNoLoad(bool);
  97.         ///  
  98.     void setInclude();
  99.         ///  
  100.     void setVerb();
  101.     ///
  102.     void setVisibleSpace(bool b);
  103.     /// return true if the file is or got loaded.
  104.     bool loadIfNeeded() const;
  105. private:
  106.         ///
  107.         enum Include_Flags {
  108.         ///
  109.         INCLUDE=0,
  110.         ///
  111.         VERB = 1,
  112.         ///
  113.         INPUT = 2,
  114.         ///
  115.         VERBAST = 3
  116.     };
  117.     
  118.     ///
  119.     bool noload;
  120.     ///
  121.         int flag;
  122.         ///
  123.     Buffer *master;
  124.     ///
  125.     LString filename;
  126. };
  127.  
  128.  
  129. inline 
  130. bool InsetInclude::isVerb() const
  131. {
  132.     return (bool)(flag==InsetInclude::VERB || flag==InsetInclude::VERBAST); 
  133. }
  134.  
  135.  
  136. inline
  137. void InsetInclude::setInput()
  138. {
  139.     if (!isInput()) {
  140.         flag = InsetInclude::INPUT;
  141.         setCmdName("input");
  142.     }
  143. }
  144.  
  145.  
  146. inline
  147. void InsetInclude::setNoLoad(bool b)
  148.         noload = b;
  149. }
  150.  
  151.  
  152. inline
  153. void InsetInclude::setInclude()
  154. {
  155.     if (!isInclude()) {
  156.         flag = InsetInclude::INCLUDE;
  157.         setCmdName("include");
  158.     }
  159. }
  160.  
  161.  
  162. inline
  163. void InsetInclude::setVerb()
  164.     if (!isVerb()) {
  165.         flag = InsetInclude::VERB;
  166.         setCmdName("verbatiminput");
  167.     }
  168. }
  169.  
  170.  
  171. inline
  172. void InsetInclude::setVisibleSpace(bool b)
  173. {
  174.         if (b && flag==InsetInclude::VERB) {
  175.         setCmdName("verbatiminput*");
  176.         flag = InsetInclude::VERBAST;
  177.     } else if (!b && flag==InsetInclude::VERBAST) {
  178.         setCmdName("verbatiminput");
  179.         flag = InsetInclude::VERB;
  180.     }
  181. }
  182. #endif
  183.